How to omit sourcemaps in Angular-CLI 6+

2019-04-26 17:52发布

问题:

I want to build with ng build without sourcemaps. In previous versions, I could use the --no-sourcemap or --sourcemap=false parameter, but now I get:

Unknown option: '--sourcemap'

How can I omit source maps in Angular-CLI 6+?

回答1:

Use --source-map . It takes default value true. So following command will not create sourcemaps:

ng build --source-map=false

Similarly --prod avoids creating sourcemaps by default but if you want to create then just use --source-map in the end to create sourcemaps.

Follow official Docs

Update:

For Angular cli 7 use below:

ng build --sourceMap=false

And if you want prod build with production config & bundling (thus don't want sourcemaps included in build folder) then use :

ng build --prod=true

Recent Official Docs



回答2:

As an alternative, open your package.json file.

Modify "test":"ng test" to "test":"ng test --source-map=false" or to "test":"ng test --sourceMap=false" for your angular CLI v6.x

Please note that it is --source-map and --sourceMap and not --source-maps which can be a usual mistake.



回答3:

You can also add sourceMap: false into the configuration of angular.json as shown below

I suppose they are false by default for production build when using Angular 6+ with cli.