66

Is there a way to disable the minification in AngularCli?

After I launch the command ng build --prod I need to have all files.js, in dist folder, separate and legible.

kampsj
  • 3,139
  • 5
  • 34
  • 56
Danieleee
  • 721
  • 1
  • 6
  • 6
  • Is there any reason against using `ng build` without the `--prod` flag? – Oliver Hanappi Apr 22 '17 at 08:39
  • What happens if you build in non-prod mode? Also, why do you need all of the separate JS? – jonrsharpe Apr 22 '17 at 08:39
  • 1
    'ng build --prod --source-map' will also generate source maps that your browser can use to show you the original code (for debugging). But using 'ng serve' (default dev mod) would be the best way to go about this. – Ahmed Musallam Apr 22 '17 at 18:22
  • 1
    Sorry, it is true that ng build disable minification. But what I want is that all files.js of each component are saved separately and not all in main.bundle.js – Danieleee Apr 23 '17 at 08:37
  • Interesting conversation. We have the same need : don't minifying (because of class renaming) some modules because of certain functionality. Any idea ? – Christophe Gigax Sep 27 '17 at 09:08
  • If --prod is your production there is serious difference. 9M main.js file drops to 1.2M with minification. – Davut Gürbüz Feb 28 '19 at 08:18

5 Answers5

71

Just do:

ng build --prod --optimization=false

That seems to do it. For more information see: https://github.com/angular/angular-cli/wiki/build

This is valid for angular 6.*

Web Dev
  • 2,677
  • 2
  • 30
  • 41
20

Note: If you use ng serve through some package.json run target, according to the manpage of Angular6 correspoding switch for this is:

ng serve --optimization=false

will speedup this bs in development noticeable

mschmoock
  • 20,084
  • 6
  • 33
  • 35
16

The responses from 2018 are now outdated. For the more recent versions of Angular (13 as of this writing), the --optimization=false flag is deprecated. Instead, you can achieve the same result as follows:

In your angular.json, you can configure it for specific environment (e.g. no optimization in dev, but optimization in prod).

      "architect": {
        "build": {
          "builder": "@angular-devkit/build-angular:browser",
          "options": {
            "optimization": false,
            ...
          }
        }
      }

You can also have more granular control on which optimizations are enabled:

"optimization": {
  "scripts": true,
  "fonts": false,
  "styles": false
}

Those too can be further refined (e.g. for styles: minify, inlineCritical)

More details here: https://angular.io/guide/workspace-config#optimization-configuration

Julien
  • 3,613
  • 2
  • 23
  • 25
9
ng build --build-optimizer=false

Above command Enables '@angular-devkit/build-optimizer' optimizations when using the 'aot' option.

More details at https://angular.io/cli/build

Chetan Laddha
  • 993
  • 8
  • 22
-3

In order to get the plain and separate and un-minified js files you just need to compile them with typescript (tsc) to your dist directory.

There is no need to use the cli build. By design Angular CLI bundles all javascript files when building.

From the cli build documentation:

All builds make use of bundling and limited tree-shaking, while --prod builds also run limited dead code elimination via UglifyJS.

kampsj
  • 3,139
  • 5
  • 34
  • 56