sass-vars-loader: Variables undefined when use sass-loader.options.data attribute

Hello! I use sass-vars-loader with Vue Cli 3 and I try to move common scss-files to app config:

const path = require('path');

module.exports = {
  chainWebpack: (config) => {
    const moduleTypes = ['vue-modules', 'vue', 'normal-modules', 'normal'];
    moduleTypes.forEach(moduleType =>
      config.module
        .rule('scss')
        .oneOf(moduleType)
        .use('@epegzz/sass-vars-loader')
        .loader('@epegzz/sass-vars-loader')
        .options({
          syntax: 'scss',
          files: [
            path.resolve(__dirname, 'src/assets/styles/contracts/variables.json'),
            path.resolve(__dirname, 'src/assets/styles/contracts/icons.json')
          ],
        })
    )
  },

  css: {
    loaderOptions: {
      sass: {
        data: `
          @import '~@/assets/styles/vars';
          @import '~@/assets/styles/util';
          @import '~@/assets/styles/func';
          @import '~@/assets/styles/mixins';
          @import '~@/assets/styles/colors';
        `,
      },
    },
  },
}

But on app loaded I have got an error: โ€œUndefined variable: $paletteโ€. It works properly, when I importing common scss-files directly, but I want to import it all in one place.

Can you help me?

About this issue

  • Original URL
  • State: open
  • Created 5 years ago
  • Comments: 19 (10 by maintainers)

Most upvoted comments

@dschox file order is now respected in v6.0.0. Thanks for your patience ๐Ÿ‘

Is it possible you can do this this year? ๐Ÿ˜‰

oh yeah, absolutely ๐Ÿ‘

The year is not over yet! ๐Ÿ˜†

@epegzz Any news on this? ๐Ÿ˜ƒ

@epegzz I think a PR is out of my league ๐Ÿ˜ƒ Is it possible you can do this this year? ๐Ÿ˜‰

Hm, this would actually not work, since the sass files always come first. Thatโ€™s a stupid design! ๐Ÿ™ˆ ๐Ÿ˜†

CleanShot 2019-08-23 at 13 45 55@2x

I could change that. Itโ€™s basically #23