0

Is it possible to enable tree shaking using ng build--prod without minifying the code? I know it is possible by using a custom webpack.config.js but I am using angular-cli with angular.json for configuration. Some suggest running the ng build --prod with --optimization=false flag but I am not sure if dead code elimination takes place with this flag

ASR
  • 421
  • 11
  • 27
  • Can you elaborate on "without code minification" - the answer may be different depending on what you are trying to do. Do you want to be able to see the source code in a production build? – ulmas May 04 '20 at 20:41
  • Yes, I want the code to be readable. When uglified/minified the code is almost illegible. – ASR May 05 '20 at 07:02

1 Answers1

0

What you are looking for is generating source maps with the transpiled/minified build. Use this option with the build:

ng build --prod --sourceMap=true

Note that this will expose your source code to the public.

You can also set that in the angular.json for different targets (production, etc.):

"architect": {
  ...
  "serve": {
    "builder": "@angular-devkit/build-angular:dev-server",
    "options": {
      "browserTarget": "web:build",
      "sourceMap": {
        "scripts": true,
        "styles": true,
        "vendor": true
      }
    },
   ...
ulmas
  • 2,203
  • 16
  • 22