Angular 7 使用 ng build --prod 缩小资产

use*_*828 7 javascript minify node.js typescript angular

JavaScript和CSS文件中/assets没有后精缩ng build --prod。有人知道我如何缩小这些文件吗?我在 angular 文档中没有看到任何内容。

Ton*_*Ngo 4

你在生产中构建的所有内容都已经缩小了,如果它没有缩小的话我认为你还没有在 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"
            }
        ]
    }
}
Run Code Online (Sandbox Code Playgroud)

然后ng build --prod再次运行