Angular CLI 1.7.2 + Webpack 4.1.0没有使用--prod构建

时间:2018-03-04 23:23:02

标签: angular webpack angular-cli angular5 webpack-4

所以我最近在angular5项目上运行ng update并将angular cli更新为1.7.2版,将webpack更新为4.1.0。我可以使用ng build构建正常但没有错误但是当我运行ng build --prod时,我收到以下错误:

78% advanced chunk optimizationD:\WORKSPACE\node_modules\webpack\lib\Chunk.js:465
                throw new Error("Chunk.entrypoints: Use Chunks.addGroup instead");
                ^

Error: Chunk.entrypoints: Use Chunks.addGroup instead
    at Chunk.set (D:\WORKSPACE\node_modules\webpack\lib\Chunk.js:465:9)
    at D:\WORKSPACE\node_modules\extract-text-webpack-plugin\dist\index.js:176:40
    at Array.forEach (<anonymous>)
    at Compilation.<anonymous> (D:\WORKSPACE\node_modules\extract-text-webpack-plugin\dist\index.js:171:18)
    at Compilation.applyPluginsAsyncSeries (D:\WORKSPACE\node_modules\tapable\lib\Tapable.js:206:13)
    at Compilation.seal (D:\WORKSPACE\node_modules\@angular\cli\node_modules\webpack\lib\Compilation.js:602:8)
    at applyPluginsParallel.err (D:\WORKSPACE\node_modules\@angular\cli\node_modules\webpack\lib\Compiler.js:504:17)
    at D:\WORKSPACE\node_modules\tapable\lib\Tapable.js:289:11
    at _addModuleChain (D:\WORKSPACE\node_modules\@angular\cli\node_modules\webpack\lib\Compilation.js:505:11)
    at processModuleDependencies.err (D:\WORKSPACE\node_modules\@angular\cli\node_modules\webpack\lib\Compilation.js:475:14)
    at _combinedTickCallback (internal/process/next_tick.js:131:7)
    at process._tickCallback (internal/process/next_tick.js:180:9)

不知道该怎么做,有什么帮助吗?如果有帮助,我可以发布webpack.config.jspackages.json

1 个答案:

答案 0 :(得分:2)

我使用Angular CLI 1.7.2将一个新项目引导到GitHub仓库中,并在每次提交中逐步更新,以使其使用Webpack 4.0.1进行构建。

https://github.com/fernandoespinosa/angular-cli-webpack4-sample/

要解决您当前的问题,您必须更新一些软件包:

npm i -D --save --force html-webpack-plugin@latest
npm i -D --save --force extract-text-webpack-plugin@4.0.0-beta.0

请注意,CommonsChunkPlugin已被弃用,因此您必须将其从 webpack.config.js 中删除。你必须ng eject这个文件并稍微玩一下。

ng eject --aot=true --target=production --build-optimizer=true