我正在尝试优化我们用作依赖的ng2-smart-table package,因为我注意到它对lodash有很大的不必要的依赖,尽管它只使用了很小的一部分lodash。
然而,当我试图让webpack bundle analyzer与他们的angular.json workspace file一起工作时,我遇到了一些问题。
如果我只是尝试运行ng build,我会得到这样的结果:
❯ ng build --statsJson
Unknown option: '--statsJson'
❯ ng build --stats-json
Unknown option: '--stats-json'现在,项目使用了一个包含以下内容的angular.json工作区文件:
{
"$schema": "./node_modules/@angular/cli/lib/config/schema.json",
"version": 1,
"newProjectRoot": "projects",
"projects": {
"ng2-smart-table": {
"projectType": "library",
"root": "projects/ng2-smart-table",
"sourceRoot": "projects/ng2-smart-table/src",
"prefix": "lib",
"architect": {
"build": {
"builder": "@angular-devkit/build-ng-packagr:build",
"options": {
"tsConfig": "projects/ng2-smart-table/tsconfig.lib.json",
"project": "projects/ng2-smart-table/ng-package.json"
}
},
...如果我尝试将"statsJson": true添加到选项中,则会出现以下错误:
❯ ng build ng2-smart-table
Schema validation failed with the following errors:
Data path "" should NOT have additional properties(statsJson).我怀疑这与使用@angular-devkit/build-ng-packagr:build而不是标准@angular-devkit/build-angular:browser的项目有关。然而,由于packagr显然不支持分析,我只是不知道如何才能生成分析文件。
发布于 2019-11-01 02:38:33
如果使用的是工作区,则需要指定项目
ng build myproject --statsJson发布于 2020-10-23 17:04:15
转到angular.json文件并检查"projects“部分。
"projects": {
"template": { <--- here
"projectType": "application",
"schematics": {},然后运行ng build template --statsJson
在您的示例中,它是ng build ng2-smart-table --statsJson
https://stackoverflow.com/questions/56672779
复制相似问题