【问题标题】:how to reduce main.*.js file after build of angular 7 project?angular 7项目构建后如何减少main.*.js文件?
【发布时间】:2020-10-29 17:57:56
【问题描述】:

在构建 angular 7 项目后,我们的 main.*.js 文件大小为 8.8 mb。我们已经在使用 gzip 压缩。您能否建议我们如何减小它的大小,以便它不会花费更多时间来加载?

【问题讨论】:

标签: node.js angular npm build


【解决方案1】:

您需要将组件划分为模块,然后使用模块延迟加载,这会将这些组件源带到单个模块并与main.*.js分开加载

【讨论】:

    【解决方案2】:

    使用aot模式构建:ng build --aot

    ng build --prod
    

    更多内容在cli docs

    另请参阅新的 Angular 引擎(最新版本):ivy

    【讨论】:

    • "scripts": { "build:ssr": "cross-env NODE_OPTIONS=--max_old_space_size=42000 npm run build:client-and-server-bundles && npm run webpack:server", " build:client-and-server-bundles": "ng build --prod --aot --optimization --build-optimizer --vendor-chunk --common-chunk --extract-licenses --extract-css -- source-map=false && ng run angular.io-example:server", "webpack:server": "webpack --config webpack.server.config.js --progress --colors", },
    • 使用上述脚本后,供应商 js 文件也为 15 mb
    猜你喜欢
    • 2020-01-02
    • 2021-08-10
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2018-05-05
    • 2018-07-11
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多