Webpack with vue-loader and sass-loader cannot import .scss files

I am trying to import some variables into a .vue component, but this will not work, and I suspect a bad webpack configuration ...

.vue

<style scoped lang="scss">
    @import "variables";
    ...

config.js

...
   {
    test: /\.vue$/,
    loader: 'vue-loader',
    options: {
      loaders: {
        'sass-loader': {
          data: '@import "variables";',
          includePaths: [
            // yes, I've tested different paths with no luck...
            '/src/scss',
            './src/scss',
            path.resolve(__dirname, '/src/scss'),
            path.resolve(__dirname, './src/scss')
          ]
        },
      },
    }
  },
  ...

I see that many others have such a need, interestingly, someday you will find a solution. It's nice to have sass in the templates, but without variables it's pretty useless ... (of course, I can just put the absolute path, it works, but what a bad practice of thought ...)

+4
source share
1 answer

I just started this in my current project, so here is the relevant section of my working webpack configuration:

  test: /\.vue$/,
  loader: 'vue-loader',
  options: {
    esModule: true,
    loaders: {
      sass: [ 'vue-style-loader',
              'css-loader',
              {
                  loader: 'sass-loader',
                  options: {
                      indentedSyntax: true;
                      data: '@import "variables";',
                      includePaths: [
                          'src/styles',
                      ],
                  },
              },
            ],
      scss: [ 'vue-style-loader',
              'css-loader',
              {
                  loader: 'sass-loader',
                  options: {
                      data: '@import "variables";',
                      includePaths: [
                          'src/styles',
                      ],
                  },
              },
            ],

vue, , . sass scss, ( drop) .

+1

Source: https://habr.com/ru/post/1680939/


All Articles