【问题标题】:Migration from Webpack 1 to 2 Errors - Angular (4.1.3) application从 Webpack 1 迁移到 2 错误 - Angular (4.1.3) 应用程序
【发布时间】:2017-10-26 19:54:48
【问题描述】:

我正在尝试将我的 Angular 应用程序从 Webpack 1 迁移到 2。在遵循 here 和 here 的更改之后。现在我收到以下元数据错误:

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, 
   ...
}

【问题讨论】:

    标签: javascript angular webpack webpack-2


    【解决方案1】:

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

    如果你想在 webpack 配置中配置 title 或 baseUrl 等内容,可以使用 HtmlWebpackPlugin,就像在 here 中使用的那样。

    【讨论】:

    • 我按照您提供的第二个链接(HtmlWebpackPlugin)工作。但我得到commonConfig 不是一个函数。 module.exports 应该是一个函数吗?
    • 它不应该是一个函数,但我可以是一个函数。这是您需要文件时得到的。在 repo 中,它是一个函数,因此您可以传入选项,如第 43 行所示。
    • 我现在看到与引导加载程序相关的错误。不知道为什么,因为我没有在配置文件的任何地方明确使用它
    猜你喜欢
    • 2017-08-23
    • 2017-12-30
    • 2016-11-04
    • 2017-03-11
    • 2018-04-27
    • 1970-01-01
    • 2018-09-20
    • 2016-12-17
    • 2019-07-21
    相关资源
    最近更新 更多