question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Add a vue-cli Configure Sass-Resources-Loader Example

See original GitHub issue

What problem does this feature solve?

I read the vue-cli docs about sass-resources-loader section and can not understand how to configure the vue-cli project for this. After some codes reading,I write these codes for that loader to work out:

//vue.config.js
var path = require('path');
module.exports = {
    chainWebpack: config => {
        config.module
            .rule('vue')
            .use('vue-loader')
            .tap(options => {
                var scssResourceLoader = {
                    loader: 'sass-resources-loader',
                    options: {
                        resources: path.resolve(__dirname, 'src/assets/_variables.scss')
                    }
                };
                options.loaders.scss.push(scssResourceLoader);
                return options;
            });
    }
}

I hope this will help others.

What does the proposed API look like?

Issue Analytics

  • State:closed
  • Created 6 years ago
  • Reactions:2
  • Comments:16 (4 by maintainers)

github_iconTop GitHub Comments

19reactions
gavinwyfcommented, Aug 18, 2018
// vue.config.js
module.exports = {
  css: {
    loaderOptions: {
      // 给 sass-loader 传递选项
      sass: {
        // @/ 是 src/ 的别名
        // 所以这里假设你有 `src/variables.scss` 这个文件
        data: `@import "@/variables.scss";`
      }
    }
  }
}
3reactions
mediaessenzcommented, Mar 31, 2018

@phoet or you just try this official parameters:

module.exports = {
    productionSourceMap: true,
    css: {
        // extract CSS in components into a single CSS file (only in production)
        extract: true,

        // enable CSS source maps?
        sourceMap: true
    }
}

You can found more options here: @vue/cli-service/lib/options.js

Read more comments on GitHub >

github_iconTop Results From Across the Web

Working with CSS - Vue CLI
Vue CLI uses PostCSS internally. You can configure PostCSS via . postcssrc or any config source supported by postcss-load-config, and configure ...
Read more >
[Solved]-Using sass-resources-loader with vue-cli v3.x-Vue.js
vue -cli@3.x uses webpack-chain to manage its webpack config. To add sass-resources-loader to the predefined webpack config. Add the following to the ...
Read more >
Using sass-resources-loader with vue-cli v3.x - iTecNote
How to use sass-resources-loader with vue-cli@3.x to add global scss variables and mixins. Best Solution.
Read more >
How to use SASS / SCSS with latest vue-cli starter project?
you install the necessary dependencies. npm install -D node-sass sass-loader. for global styles, simply import the file into main.js :.
Read more >
Globally Load SASS into your Vue.js Applications
Vue -cli allows to modify its configuration by creating a vue.config.js file at the root of the project that exports an object with...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found