1

webpack.base.conf.js

module: {
rules: [
  {
    test: /\.vue$/,
    loader: 'vue-loader',
    options: {
      loaders: {
        scss: 'vue-style-loader!css-loader!sass-loader',
        sass: 'vue-style-loader!css-loader!sass-loader?indentedSyntax'
      }
    }
  },
  {
    loader: 'sass-resources-loader',
    options: {
      resources: path.resolve(__dirname, '../src/assets/scss/_variables.scss')
    }
  },

My "variables" file starts to load, but then i get this error:

Module parse failed: Unexpected character '#' (1:8)
You may need an appropriate loader to handle this file type.
| $white: #ffffff;
| 
| // The Vue build version to load with the `import` command

I use this manual:

https://vue-loader-v14.vuejs.org/en/configurations/pre-processors.html

vue version: 2.93

2 Answers 2

1

Eventually i created project from scratch using vue-cli@3 and added to vue.config.js this code:

const path = require('path');

module.exports = {
  chainWebpack: config => {
    const oneOfsMap = config.module.rule('scss').oneOfs.store
    oneOfsMap.forEach(item => {
      item
        .use('sass-resources-loader')
        .loader('sass-resources-loader')
        .options({
          resources: [
            path.resolve(__dirname, './src/assets/scss/_variables.scss'),
            path.resolve(__dirname, './src/assets/scss/_mixins.scss'),
          ]
        })
        .end()
    })
  }
}
Sign up to request clarification or add additional context in comments.

Comments

0

You might want to add it to a vue.config.js file in your root directory. If the file doesn't exist, create it and add something along the lines of this (my config):

module.exports = {
css: {
    loaderOptions: {
      sass: {
        data: `
          @import "@/assets/_variables.scss";
        `
      }
    }
  }
};

4 Comments

Thanks, but it is not working for me. Should i make some changes in my webpack.base.conf.js ?
Have you installed with vue cli? If you're using the config above, you won't need your code in webpack config. Make sure you have the following under devDependencies in package.json as well: "css-loader": "^1.0.0", "sass-loader": "^7.1.0",
Yes. I have these dependencies. It looks like webpack ignores my vue.config.js .
You should now use "prependData" instead of "data" which is deprecated now (sass-loader v8)

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.