json 使用webpack bundle analyzer和angular workspace文件

qncylg1j  于 4个月前  发布在  Webpack
关注(0)|答案(3)|浏览(93)

我试图优化ng2-smart-table package,我们使用它作为依赖,因为我注意到它对lodash有很大的不必要的依赖,即使它只使用了lodash的一小部分。
然而,当我试图让webpack bundle analyzer与他们的angular.jsonworkspace 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显然不支持分析,我只是不知道如何生成我的分析文件。

vof42yt1

vof42yt11#

至于错误本身:根据Angular CLI docs--stats-json选项不能用于库项目类型。
该命令可用于生成“application”或“library”类型的项目。用于生成library时,将调用不同的生成器,并且仅应用ts-configconfigurationwatch选项。所有其他选项仅适用于生成应用程序。

yacmzcpb

yacmzcpb2#

如果您使用的是工作区,

ng build myproject --statsJson

字符串

qzwqbdag

qzwqbdag3#

转到angular.json文件并检查“projects”部分。

"projects": {
    "template": { <--- here
        "projectType": "application",
        "schematics": {},

字符串
然后运行ng build template --statsJson
在你的情况下,它是ng build ng2-smart-table --statsJson

相关问题