从Webpack 1迁移到2个错误 - Angular(4.1.3)应用程序

时间:2017-05-26 02:46:15

标签: javascript angular webpack webpack-2

我尝试将我的角度应用程序从Webpack 1迁移到2.从herehere进行更改后。现在我的元数据出现以下错误:

Invalid configuration object. Webpack has been initialised using a 

configuration object that does not match the API schema.
 - configuration has an unknown property 'metadata'. These properties are valid:
   object { amd?, bail?, cache?, context?, dependencies?, devServer?, devtool?, entry, externals?, loader?, module?, name?, node?, output?, performance?, plugins?, profile?, recordsInputPath?, recordsOutputPath?, recordsPath?, resolve?, resolveLoader?, stats?, target?, watch?, watchOptions? }
   For typos: please correct them.
   For loader options: webpack 2 no longer allows custom properties in configuration.
     Loaders should be updated to allow passing options via loader options in module.rules.
     Until loaders are updated one can use the LoaderOptionsPlugin to pass these options to the loader:
     plugins: [
       new webpack.LoaderOptionsPlugin({
         // test: /\.xxx$/, // may apply this only for some modules
         options: {
           metadata: ...
         }
       })
     ]

但是我不确定它指向哪个webpack配置文件,因为我有一个用于不同环境的文件。

在webpack.common.js中:

const METADATA = {
   title:
   baseUrl: 
}
module.exports = {
   metadata: METADATA,
   ...
}

在其他webpack文件中(对于开发,本地,制作,测试),我定义const METADATA并在module.exports内,我有

webpackMerge(commonConfig, {
   metadata: METADATA, 
   ...
}

1 个答案:

答案 0 :(得分:0)

错误消息是指传递给webpack的config。我猜你正在使用webpackMerge,因为你有一个共同的配置。所以基本上它会引用所有配置文件,因为元数据不是允许的配置属性。 Here您找到了完全成熟的配置。从配置中删除元数据属性时,错误消息应该消失。

如果要在webpack配置中配置title或baseUrl之类的东西,可以像在here中一样使用HtmlWebpackPlugin。