使用弹出的Angular 4应用程序进行生产编译会生成大文件 [英] Production compilation with ejected Angular 4 application produces large files
问题描述
ng build --prod
Angular CLI命令在Angular4应用程序中生成高度压缩的javascript文件.
ng build --prod
Angular CLI command produces highly compressed javascript files in Angular4 application.
使用ng eject
命令弹出应用程序时,Angular CLI命令消失了,剩下npm脚本(npm run build
命令来构建应用程序),但是不幸的是,该命令会输出非生产版本.
When the application is ejected using ng eject
command, Angular CLI commands are gone and we are left with npm scripts( npm run build
command to build the app), but unfortunately that command outputs a non-production build.
我尝试直接运行webpack -p
命令,但是与ng build --prod
命令的输出相比,输出结果文件要稍大 .
I tried running webpack -p
command directly but the output result files are slightly larger compared to the output of ng build --prod
command.
如何在弹出的应用程序上获得与ng build --prod
命令等效的压缩?哪些命令/参数可以产生这样的结果?
How to get a compression equivalent of ng build --prod
command but on an ejected application? What command/arguments can produce such results?
推荐答案
您可以使用以下命令弹出Webpack配置的生产版本:
You can eject the production version of the webpack config by using the following command:
ng eject --prod
编辑
如果您要同时使用开发和弹出的webpack配置的生产版本,请执行以下操作:
If you want to use both the development & production versions of the ejected webpack config, do the following:
- 备份您现有的 package.json
-
执行
ng eject --prod
(这将弹出webpack配置的生产版本)
- Backup your existing package.json
Execute
ng eject --prod
(this will eject the production version of webpack config)
将重命名的webpack.config.json重命名为 webpack.config-prod.json
您现在剩下的是制作& Webpack配置的开发版本.现在,要编译您的Angular项目以进行生产,请执行webpack --config webpack.config-prod.js
,并且您也可以将其轻松添加到package.json脚本中.
You're now left with a production & development version of your webpack configs. Now, to compile your Angular project for production, execute webpack --config webpack.config-prod.js
and you can also add this to your package.json scripts for ease.
但是,这可能不是完美的方法,但这就是我所做的.如果有更好的版本,请随时进行编辑.
这篇关于使用弹出的Angular 4应用程序进行生产编译会生成大文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!