Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Vue CLI 3 sass-resources-loader - Options.loaders undefined

I was able to successfully configure a new Vue project using the 3.0 version of the CLI to use sass-resource-loader a few weeks ago using the information posted here: Using sass-resources-loader with vue-cli v3.x

However, after updating everything today I'm encountering the following error when running npm run serve:

TypeError: Cannot read property 'scss' of undefined

the only options that seem to be getting passed into .tap(options) are:

{ compilerOptions: { preserveWhitespace: false } }

I don't currently know enough about chainWebpack to effectively debug, but I'm working on it. If anyone has any insights into what's changed to cause this error, it'd be greatly appreciated.

my vue.config.js:

const path = require('path')

module.exports = {
  chainWebpack: (config) => {
    config
      .module
      .rule('vue')
      .use('vue-loader')
      .tap((options) => {
        console.log(options)
        options.loaders.scss = options.loaders.scss.concat({
          loader: 'sass-resources-loader',
          options: {
            resources: [
              path.resolve('./src/scss/_variables.scss'),
              path.resolve('./src/scss/_mixins.scss')
            ]
          },
        })
        return options
      })
    config
      .module
      .rule('scss')
      .use('sass-resources-loader')
      .loader('sass-resources-loader')
      .options({
        resources: [
          path.resolve('./src/scss/_variables.scss'),
          path.resolve('./src/scss/_mixins.scss')
        ]
      })
  }
}
like image 679
Andrew Boyd Avatar asked May 23 '18 15:05

Andrew Boyd


1 Answers

You use [email protected], this probably means that your project uses [email protected] Since version 15, the vue-loader does not need additional configs for loaders. You can configure only your main webpack loaders.

const path = require('path')

module.exports = {
  chainWebpack: (config) => {
    config
      .module
      .rule('scss')
      .use('sass-resources-loader')
      .loader('sass-resources-loader')
      .options({
        resources: [
          path.resolve('./src/scss/_variables.scss'),
          path.resolve('./src/scss/_mixins.scss')
        ]
      })
  }
}

You can also inspect webpack configs using the vue inspect or ./node_modules/.bin/vue-cli-service inspect commands.

like image 160
Ruslan Avatar answered Nov 12 '22 13:11

Ruslan