Angular-cli: Default to production builds

Created on 19 May 2019  Â·  9Comments  Â·  Source: angular/angular-cli

🚀 Feature request

I know this is tough due to it being a breaking change with the ecosystem, but I think ng build should do a production build by default.

Command (mark with an x)

- [x] build

Description

Most of the time, developers should be building for production, and serving for development. It would save a lot of time overall if ng build defaulted to production mode.

Describe the solution you'd like

During the update process to 9 (or some other version), prompt the user if they want to keep the current behavior or migrate to the new behavior, and then default all new projects with ng new to production by default.

Describe alternatives you've considered

None

angulacli feature

Most helpful comment

Hi @mgechev @filipesilva @StephenFluin

I think we should make ng build --prod as default in angular-cli v9

We maintain an angular component library and we almost could receive dozens of the same question every week, that is

Why the angular build out is so big(3MB or larger)? and why the performance is so poor? we do not want to use it any longer

when they run ng build or npm run build

We have to explain that prod mode is not the default mode, plz use ng build --prod instead.

The ng build --prod has been detailed in the official documentation, but many new users just skip the document and just run npm run build (equals ng build) in the project generated by @angular/cli.

Angular may lose quite a lot of users due to the misunderstanding of ng build.
I think it is time to make --prod mode default in command ng build.

All 9 comments

We actually followed this exact reasoning in 1.6, and some users were caught by surprise in a nasty way (https://github.com/angular/angular-cli/issues/10191), prompting us to revert it (https://github.com/angular/devkit/commit/b9704dc16efcbdfa3ccad59056709331bb2c4f50).

I can't imagine doing this change now would go any better since users have been used to npm run build not doing prod builds for much longer now.

@alexeagle WDYT?

Based on our discussion today, the feature makes a lot of sense. We should be very explicit in the way we communicate that we're using --prod.

@mgechev Are you saying the right behavior is to default to non-prod or to production mode?

Build —> production by default
Serve —> development by default

When the changeover happens (9.0? Sooner?) the concept would be that in addition to messaging in the release notes, a informational message would be displayed on build execution to provide ample opportunity to inform the user of the change in behavior.

Using our current setup, we could make the default options for build in angular.json contain the production settings, and have a separate dev configuration for development settings. Then ng serve would target the dev configuration for its build options.

We'd also have to provide good messages in the CLI about this. Users are used to using the --prod flag.

Awesome! Perhaps we could consider an update schematic that adds a "legacyBuildDefault"= true somewhere to existing applications that update to help folks with the transition.

This requires documentation changes and communicating to the user.

v9 with Ivy might not be the right time for this.

@StephenFluin - It would be good to have a design doc for this.

Hi @mgechev @filipesilva @StephenFluin

I think we should make ng build --prod as default in angular-cli v9

We maintain an angular component library and we almost could receive dozens of the same question every week, that is

Why the angular build out is so big(3MB or larger)? and why the performance is so poor? we do not want to use it any longer

when they run ng build or npm run build

We have to explain that prod mode is not the default mode, plz use ng build --prod instead.

The ng build --prod has been detailed in the official documentation, but many new users just skip the document and just run npm run build (equals ng build) in the project generated by @angular/cli.

Angular may lose quite a lot of users due to the misunderstanding of ng build.
I think it is time to make --prod mode default in command ng build.

Consensus seems to be that this is a good idea which we should do. At this point we pretty much just need to actually implement it.

Was this page helpful?
0 / 5 - 0 ratings