V
V
Viktor Arkhipov2018-04-07 07:08:21
webpack
Viktor Arkhipov, 2018-04-07 07:08:21

How to include sass-resources-loader in vue-cli?

Hello, I'm using vue-cli.
I decided to include sass-resources-loader to import variables into the component, but I have no idea how to do it, because no access to webpack config, only vue.config.js.
The documentation suggests merging my settings with cli settings, but no matter how I tried, I couldn't.

Answer the question

In order to leave comments, you need to log in

1 answer(s)
V
Victor Arkhipov, 2018-04-07
@paul-smith

In general, here is the solution, if someone was also interested. vue.config.js
file

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

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question