I have freshly installed angular-cli 1.0.0.beta.17 (latest one), start new project, able to serve project on port 4200 with no problems - just standard "app works!" message.
However when I try to build for production this empty and generic application by using command ng build --prod
I do not have main.*.js file created at all and have a few screens of warnings like:
This is a brand new empty project - I did not have a chance to break anything yet...
How to build production version ?
To build your application for production, use the build command. By default, this command uses the production build configuration. This command creates a dist folder in the application root directory with all the files that a hosting service needs for serving your application.
ng build now uses the production configuration by default. You no longer need to pass the --prod option to the command.
Updated for Angular v6+
# Prod - these are equivalent ng build --configuration=production ng build --c=production ng build --prod=true # Dev - and so are these ng build --configuration=development ng build --c=development ng build --prod=false ng build
More flag settings here
Per Angular-cli's github wiki v2+, these are the most common ways to initiate a dev and production build
# Prod these are equivalent ng build --target=production --environment=prod ng build --prod --env=prod ng build --prod # Dev and so are these ng build --target=development --environment=dev ng build --dev --env=dev ng build --dev ng build
There are different default flags that will affect --dev vs --prod builds.
Flag --dev --prod --aot false true --environment dev prod --output-hashing media all --sourcemaps true false --extract-css false true
--prod
also sets the following non-flaggable settings:
.angular-cli.json
. process.env.NODE_ENV
in modules with the production
value (this is needed for some libraries, like react). I need to do some troubleshooting in order to get AOT working. When I ran:
ng build --prod --aot=false
I would get will return a error similar to
Module not found: Error: Can't resolve './$$_gendir/app/app.module.ngfactory'
Originally, I had to do some project refactoring to get AOT to work. However, they may be a fix if you are encountering this error. Try
npm i [email protected]
https://github.com/angular/angular-cli/issues/7113
Try using: ng build --target=production This should work.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With