繁体   English   中英

Vue.js:vue.config.js 中的无效选项:不允许使用“插件”

[英]Vue.js: Invalid options in vue.config.js: "plugins" is not allowed

我有一个 webpack 项目,我想使用 Stylelint 进行 SCSS linting。 我已按照 Stylelint 网站上的说明进行安装:

"stylelint": "^12.0.1",
"stylelint-webpack-plugin": "^1.1.2",

然后我把它放在 vue.config.js 中:

plugins: [
  new StylelintPlugin({
    files: '**/*.s?(a|c)ss'
  })
],

当我启动服务器时,我得到了这个:

Invalid options in vue.config.js: "plugins" is not allowed

我搜索了高低,但没有找到任何东西。 任何帮助,将不胜感激。

这是 vue.config.js:

const StylelintPlugin = require('stylelint-webpack-plugin')

module.exports = {

  plugins: [
    new StylelintPlugin({
      files: '**/*.s?(a|c)ss'
    })
  ],

  assetsDir: 'asset',

  configureWebpack: config => {
    config.entry = '@/wrapper/main.js'
  },

  chainWebpack: config => {
    config.plugins.delete('prefetch')
  },

  lintOnSave: undefined,
  runtimeCompiler: true
}

调整 webpack 配置的最简单方法是为 vue.config.js 中的configureWebpack选项提供一个对象:

// vue.config.js
module.exports = {
  configureWebpack: {
    plugins: [new MyAwesomeWebpackPlugin()]
  }
}

该对象将使用 webpack-merge 合并到最终的 webpack 配置中。

查看https://cli.vuejs.org/guide/webpack.html了解更多信息。

你有没有尝试过这种语法:

const StylelintPlugin = require('stylelint-webpack-plugin')

module.exports = {

  assetsDir: 'asset',

  configureWebpack: config => {
    config.entry = '@/wrapper/main.js'
  },

  chainWebpack: config => {
    config.plugins.delete('prefetch')

    config.plugin('stylelint').use(StylelintPlugin, [
      {
        files: '**/*.s?(a|c)ss'
      }
    ])
  },

  lintOnSave: undefined,
  runtimeCompiler: true
}

这就是我们设法让它发挥作用的方式。

也许这会帮助某人

// vue.config.js
module.exports = {
 configureWebpack: {
  plugins: [
   new MyAwesomeWebpackPlugin()
  ]
 }
}

// In my case i was doing below and was facing the same error
const path = require('path')
const PrerenderSPAPlugin = require('prerender-spa-plugin')

module.exports = {
    configureWebpack: {
        plugins: [
               new PrerenderSPAPlugin({
                // Required - The path to the webpack-outputted app to prerender.
                staticDir: path.join(__dirname, 'dist'),
                // Required - Routes to render.
                routes: ['/', '/page-path', '/another-page'],
            })
        ]
    },
    lintOnSave: false
}

https://cli.vuejs.org/guide/webpack.html#simple-configuration

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM