在Angular 14中,可以使用“extract-i18n”代替“ExtractCss”,来提取出Angular应用程序中的CSS。
示例代码:
在angular.json文件中,使用“i18nExtract”选项来设置提取CSS的方式。在该选项下,可以使用“extractCss”属性来指定是否要提取CSS,以及提取后的CSS的输出目录。
例如,以下angular.json文件中,提取CSS后的文件将被保存在“dist/my-app/styles”目录下:
{ "$schema": "./node_modules/@angular/cli/lib/config/schema.json", "version": 1, "newProjectRoot": "projects", "projects": { "my-app": { "root": "", "sourceRoot": "src", "projectType": "application", "prefix": "app", "schematics": {}, "architect": { "build": { "builder": "@angular-devkit/build-angular:browser", "options": { "outputPath": "dist/my-app", "index": "src/index.html", "main": "src/main.ts", "polyfills": "src/polyfills.ts", "tsConfig": "src/tsconfig.app.json", "assets": [ "src/favicon.ico", "src/assets" ], "styles": [ "src/styles.scss" ] }, "configurations": { "production": { "fileReplacements": [ { "replace": "src/environments/environment.ts", "with": "src/environments/environment.prod.ts" } ], "extractCss": true, //提取CSS选项 "outputHashing": "all", "sourceMap": false, "namedChunks": false, "aot": true, "extractLicenses": true, "vendorChunk": false, "buildOptimizer": true, "budgets": [ { "type": "initial", "maximumWarning": "2mb", "maximumError": "5mb" } ] } } } }