Skip to content

feat(@angular-devkit/build-angular): remove Closure compiler i18n code for ivy - #13905

Merged
vikerman merged 1 commit into
masterfrom
feat-closure-i18n-option
Mar 13, 2019
Merged

vikerman merged 1 commit into
masterfrom
feat-closure-i18n-option

Conversation

@ocombe

@ocombe ocombe commented Mar 13, 2019 •

Copy link
Copy Markdown
Contributor

For runtime i18n with ivy we generate code for both Closure compiler (used at Google) and for external people that don't use Closure compiler.
We added a new global flag named ngI18nClosureMode that allows uglify (and Closure compiler) to effectively tree-shake all of the code that isn't used in the current setup.
By default we remove all of the Closure compiler code because we assume that it won't be used.

Required for angular/angular#28689.

…e for ivy

For runtime i18n with ivy we generate code for both Closure compiler (used at Google) and for external people that don't use Closure compiler.
We added a new global flag named `ngI18nClosureMode` that allows uglify (and Closure compiler) to effectively tree-shake all of the code that isn't used in the current setup.
By default we remove all of the Closure compiler code because we assume that it won't be used.
@ocombe
ocombe requested a review from mhevery March 13, 2019 15:53
@ocombe ocombe added area: @angular-devkit/build-angular target: major This PR is targeted for the next major release labels Mar 13, 2019
compress: (buildOptions.platform == 'server' ? {
global_defs: {
ngDevMode: false,
ngI18nClosureMode: false,

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What happens if this isn't added? Are bundles bigger or are they broken?

@ocombe ocombe Mar 13, 2019 •

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

just bigger (it breaks the integration test on angular right now because the size diff is >1%, but other than that everything works)

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

For how long is this flag expected to be around? Is it part of the necessary tooling for Ivy in general, or is it expected to not be necessary after a certain version?

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@filipesilva ngI18nClosureMode will be around for as long as we want to support goog.getMsg. The reason we need this is because we generate

let greeting;
if (ngI18nClosureMode) {
  const MSG_greeting = goog.getMsg('Hello');
} else {
  greeting = localize`Hello`;
}

We need to generate the above because we need to ship the code in the above format to NPM so that developers which download a 3P library can choose to compile it with closure or without.

Come to think of it both ngDevMode and ngI18nClosureMode need to be defined only for the final application but NOT for library compilations. We want to make sure that when we ship things into NPM ngDevMode and ngI18nClosureMode are preserved in the source code, because it is only the application developer who can make a choice if they are building a debug build or production and if they are using goog.getMsg or something else.

What is the current best practice for building an angular library? Would the above settings apply? If so can we have a different pass for libraries which do not set these values?

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Libraries use a separate pipeline. This one is just for apps.

compress: (buildOptions.platform == 'server' ? {
global_defs: {
ngDevMode: false,
ngI18nClosureMode: false,

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@filipesilva ngI18nClosureMode will be around for as long as we want to support goog.getMsg. The reason we need this is because we generate

let greeting;
if (ngI18nClosureMode) {
  const MSG_greeting = goog.getMsg('Hello');
} else {
  greeting = localize`Hello`;
}

We need to generate the above because we need to ship the code in the above format to NPM so that developers which download a 3P library can choose to compile it with closure or without.

Come to think of it both ngDevMode and ngI18nClosureMode need to be defined only for the final application but NOT for library compilations. We want to make sure that when we ship things into NPM ngDevMode and ngI18nClosureMode are preserved in the source code, because it is only the application developer who can make a choice if they are building a debug build or production and if they are using goog.getMsg or something else.

What is the current best practice for building an angular library? Would the above settings apply? If so can we have a different pass for libraries which do not set these values?

@vikerman
vikerman merged commit 3d8064b into master Mar 13, 2019
@ocombe
ocombe deleted the feat-closure-i18n-option branch March 14, 2019 15:28
@angular-automatic-lock-bot

Copy link
Copy Markdown

This issue has been automatically locked due to inactivity.
Please file a new issue if you are encountering a similar or related problem.

Read more about our automatic conversation locking policy.

This action has been performed automatically by a bot.

@angular-automatic-lock-bot angular-automatic-lock-bot Bot locked and limited conversation to collaborators Sep 12, 2019
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

area: @angular-devkit/build-angular target: major This PR is targeted for the next major release

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants