首页 > 解决方案 > Angular 7 使用 ng build --prod 缩小资产

问题描述

中的JavaScript 和 CSS 文件/assetsng build --prod. 有人知道我可以如何缩小这些文件吗?我在角度文档中看不到任何内容。

标签: javascriptnode.jsangulartypescriptminify

解决方案


如果没有缩小,你在生产中构建的所有东西都已经缩小了我认为你没有在 angular.json 中打开配置。您可以在 angular.json 中使用这些配置

"configurations": {
    "production": {
        "fileReplacements": [
            {
                "replace": "src/environments/environment.ts",
                "with": "src/environments/environment.prod.ts"
            }
        ],
        "optimization": true,
        "outputHashing": "all",
        "sourceMap": false,
        "extractCss": true,
        "namedChunks": false,
        "aot": true,
        "extractLicenses": true,
        "vendorChunk": true,
        "buildOptimizer": true,
        "serviceWorker": true,
        "deleteOutputPath": true,
        "budgets": [
            {
                "type": "initial",
                "maximumWarning": "2mb",
                "maximumError": "5mb"
            }
        ]
    }
}

然后ng build --prod再次运行


推荐阅读