2017-05-26 105 views
1

我試圖將我的角度應用程序從Webpack 1遷移到2.在遵循herehere的更改之後。現在我發現了以下錯誤元數據:從Webpack 1遷移到2錯誤 - Angular(4.1.3)應用程序

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

回答

0

的錯誤消息是指傳遞給webpack的配置。我想你正在使用webpackMerge,因爲你有一個共同的配置。所以基本上它會引用所有的配置文件,因爲元數據不是允許的配置屬性。 Here你會發現一個完全成熟的配置。從配置中刪除元數據屬性時,錯誤消息應該消失。

如果要在webpack配置中配置標題或baseUrl之類的東西,可以使用HtmlWebpackPlugin,如here中所使用的那樣。

+0

我跟着你提供的第二個鏈接(HtmlWebpackPlugin)工作。但我得到'commonConfig'不是一個函數。 'module.exports'應該是一個函數嗎? – user3344978

+0

它不應該是一個功能,但我可以是一個功能。這是你需要文件時得到的。在回購作爲一個函數,使你可以通過選項,你可以看到第43行。 – ShabbY

+0

我現在看到有關引導程序加載器的錯誤。不知道爲什麼,因爲我沒有明確地在配置文件中的任何地方使用它 – user3344978