angular-cli: ng build --prod does NOT minify / uglify / remove comments using angular-cli 6 beta

Versions

Angular CLI: 6.0.0-beta.5
Node: 9.7.1
OS: darwin x64
Angular: 5.2.9
... animations, common, compiler, compiler-cli, core, forms
... http, language-service, platform-browser
... platform-browser-dynamic, router

@angular/cli: 6.0.0-beta.5
@angular-devkit/build-optimizer: 0.4.5
@angular-devkit/core: 0.4.5
@angular-devkit/schematics: 0.4.5
@ngtools/json-schema: 1.2.0
@ngtools/webpack: 6.0.0-beta.5
@schematics/angular: 0.4.5
@schematics/package-update: 0.4.5
typescript: 2.5.3
webpack: 4.0.1

Repro steps

  • npm install -g @angular/cli@next
  • ng new project
  • cd project
  • ng build --prod (or npm run build)

Also tested:

  • npm install -g @angular/cli@next
  • ng new project
  • cd project
  • ng update --next
  • ng build --prod (or npm run build)

And optional:

  • change "target" from "es5" to "es2015" in tsconfig.json

Observed behavior

$ ng build --prod
 10% building modules 3/3 modules 0 active(node:62415) DeprecationWarning: Tapable.plugin is deprecated. Use new API on `.hooks` instead
Date: 2018-03-15T10:28:55.547Z                                                            
Hash: 3474e7c683382f9506ba
Time: 4039ms
chunk {main} main.js, main.js.map (main) 9.48 kB [initial] [rendered]
chunk {polyfills} polyfills.js, polyfills.js.map (polyfills) 224 kB [initial] [rendered]
chunk {runtime} runtime.js, runtime.js.map (runtime) 5.09 kB [entry] [rendered]
chunk {styles} styles.js, styles.js.map (styles) 15.5 kB [initial] [rendered]
chunk {vendor} vendor.js, vendor.js.map (vendor) 2.71 MB [initial] [rendered]

The resulting file sizes vary a little bit, depending on the used settings (angular 5, angular 6 beta, es5 or es2015).

Desired behavior

Much smaller bundle sizes.

Mention any other details that might be useful (optional)

When looking at the generated .js files, I can see lot’s of whitespaces, comments, etc. pp. Though I guess that uglify is not running.

There’s no error in the output. The only warning in the output (you can see above) is DeprecationWarning: Tapable.plugin is deprecated. Use new API on .hooks instead

The same results could be observed when using @angular/cli: 6.0.0-beta.4.

About this issue

  • Original URL
  • State: closed
  • Created 6 years ago
  • Reactions: 3
  • Comments: 18 (3 by maintainers)

Most upvoted comments

Same issue here, index.html is not minified. For now I minified it manualy

@toni-rmc @samithaf the --target and --environment options are not present in Angular CLI 6 final.

You should be able to do ng build --prod and get a production build. If you have a another configuration you want to use instead, use ng build --configuration=configuration-name.

--prod indeed does nothing in beta.5. That regression was temporarily introduced in https://github.com/angular/angular-cli/pull/9707 as part of a command runner update.

We’re still missing the followup PR https://github.com/angular/angular-cli/pull/9883 that moves the finishes moving the build system and re-enabled --prod.

The workaround for now is to use --target=production instead. It should do everything that --prod was doing, since --prod was just shorthand for --target=production. There is no need to also set the environment separately.

Ok, so I have fixed the issue referencing the environment in the “src/environments/environment” not that one in the “src/app/environment”.

I’m viewing the index.html in Sublime not trough Chrome. And it is not minified when using production build, at least in my case.

It definitely works (as of latest bits) - but if you have pretty print enabled in Chrome it can look as though it isn’t.

The clue is here in the tab above the javascript code panel:

image

If you’re seeing :formatted then open the js file in a new window to verify it is indeed minified and disable the pretty print feature if you wish.

I’m simply running ng serve --prod for this example.

@filipesilva I have tested and yes bundled files are indeed minified and comments removed, although index.html is not, it stays the same in production build.