vue.config.js: “plugins” is not allowed

problem

  • vue-cli 创建vue工程,生成 vue.config.js
  • 需要再 vue.config.js 中使用 ModuleFederationPlugin
  • 按照 webpack 官方配置 此plugin后 重启服务
  • 报错信息如下
$ vue-cli-service serve  
 ERROR  Invalid options in vue.config.js: "plugins" is not allowed  
error Command failed with exit code 1.  

reason

vue.config.js 不等于 webpack 配置

solution

在 plugins 外包裹一层 configureWebpack

module.exports = {
    configureWebpack: {  
        plugins: [  
        new ModuleFederationPlugin({  
            name: "app2",  
            remotes: {  
            app1: "app1@http://localhost:8080/remoteEntry.js",  
            }  
        })  
        ]  
    }  
}  

关于configureWebpack(Type: Object | Function)

  • 如果传入参数是:对象,则会通过 webpack-merge 合并到最终的配置中
  • 如果传入参数是:函数,则会接收被解析的配置作为参数
Logo

前往低代码交流专区

更多推荐