2

I am trying to optimize the ng2-smart-table package, which we are using as a dependency, as I have noticed it has a big unnecessary dependency on lodash, even though it only uses a tiny portion of lodash.

However, I'm running into some issues when trying to get webpack bundle analyzer to work with their angular.json workspace file.

If I just try to run ng build I get this:

❯ ng build --statsJson
Unknown option: '--statsJson'
❯ ng build --stats-json
Unknown option: '--stats-json'

Now, the project uses an angular.json workspace file with the following contents:

{
  "$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"
          }
        },
        ...

If I try to add "statsJson": true to the options I get this error:

❯ ng build ng2-smart-table
Schema validation failed with the following errors:
  Data path "" should NOT have additional properties(statsJson).

I suspect it has something to do with the project using @angular-devkit/build-ng-packagr:build rather than the standard @angular-devkit/build-angular:browser. However, since the packagr apparently doesn't support analysis I just don't know how I can get my analysis file generated.

pius
  • 2,344
  • 1
  • 23
  • 25
  • you may want to use `lodash-es` its probably will better reduce amount of used lodash code if you use only few functions – Xesenix Jun 19 '19 at 20:34

2 Answers2

-1

You need to specify project if you are using a workspace such as

ng build myproject --statsJson
Scott Walter
  • 9,426
  • 4
  • 18
  • 23
-1

Go to angular.json file and check "projects" section.

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

Then run ng build template --statsJson

In your case it's ng build ng2-smart-table --statsJson

Kuzenko Lubko
  • 1,961
  • 1
  • 20
  • 26