Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

run strict compilation in ng build angular

I'm using angular-cli in my project. I have these two configs in my package.json :

"scripts": {
  "ng": "ng",
  "build": "ng build --base-href /test/",
  "prod": "ng build --prod --base-href /test/"
}

--prod detects compilation problems (like dead code) as it's said in angular documentation but it's not run in the build command that we use in development mode (actually we use npm start but it does the same thing).

This results in problems detected too late in our continuous delivery tool instead of during development.

I don't want to add the --prod for developement angular compilation tasks and i tried to see it there are options in the "tsconfig" file documentation but i didn't find any.

I read that --prod launches an uglification with uglifyJs which runs this strict compilation.

How can i tell angular to launch a strict compilation in my development "build" task the same way it's executed in --prod ? (i also tried the "user strict mode" in my files but didn't change anything).

I'm using angular 5 with the Typescript 2.x version.

Thank you in advance.

like image 588
batmaniac Avatar asked Jan 24 '26 12:01

batmaniac


1 Answers

All you have to do is add the --aot flag to any time you run a build which should have stricter checking. For example, your scripts could be configured as:

"scripts": {
  "ng": "ng",
  "build": "ng build --aot --base-href /test/",
  "prod": "ng build --prod --base-href /test/"
}
like image 148
bsplosion Avatar answered Jan 27 '26 00:01

bsplosion



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!