草庐IT

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

coder 2024-05-14 原文

几周前,我能够使用 3.0 版 CLI 成功配置一个新的 Vue 项目以使用 sass-resource-loader,使用此处发布的信息:Using sass-resources-loader with vue-cli v3.x

但是,在今天更新所有内容之后,我在运行 npm run serve 时遇到以下错误:

类型错误:无法读取未定义的属性“scss”

似乎传递给 .tap(options) 的唯一选项是:

{ compilerOptions: { preserveWhitespace: false } }

我目前对 chainWebpack 的了解还不足以有效地进行调试,但我正在努力。如果有人对导致此错误的更改有任何见解,我们将不胜感激。

我的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')
        ]
      })
  }
}

最佳答案

你使用了vue-cli@3.x,这可能意味着你的项目使用了vue-loader@15.x Since version 15 , vue-loader 不需要额外的加载器配置。 您只能配置主要的 webpack 加载器。

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.

关于javascript - Vue CLI 3 sass-resources-loader - Options.loaders undefined,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/50492833/

有关javascript - Vue CLI 3 sass-resources-loader - Options.loaders undefined的更多相关文章

随机推荐