Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions integration/terser/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
core.min.js
16 changes: 16 additions & 0 deletions integration/terser/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
{
"name": "terser",
"version": "0.0.0",
"scripts": {
"test": "node test.js"
},
"private": true,
"dependencies": {
"@angular/core": "file:../../dist/packages-dist/core",
"@angular/compiler": "file:../../dist/packages-dist/compiler",
"@angular/compiler-cli": "file:../../dist/packages-dist/compiler-cli",
"rxjs": "file:../../node_modules/rxjs",
"terser": "3.17.0",
"zone.js": "file:../../node_modules/zone.js"
}
}
25 changes: 25 additions & 0 deletions integration/terser/test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
const readFileSync = require('fs').readFileSync;
const writeFileSync = require('fs').writeFileSync;
const resolve = require('path').resolve;
const Terser = require('terser');
const GLOBAL_DEFS_FOR_TERSER = require('@angular/compiler-cli').GLOBAL_DEFS_FOR_TERSER;

const outputPath = resolve(__dirname, './core.min.js');
const pathToCoreFesm5 = resolve(__dirname, './node_modules/@angular/core/fesm5/core.js');
const coreFesm5Content = readFileSync(pathToCoreFesm5, 'utf8');
// Ensure that Terser global_defs exported by compiler-cli work.
const terserOpts = {
compress: {
module: true,
global_defs: GLOBAL_DEFS_FOR_TERSER
}
};
const result = Terser.minify(coreFesm5Content, terserOpts);
writeFileSync(outputPath, result.code);

for (const def of Object.keys(GLOBAL_DEFS_FOR_TERSER)) {
if (result.code.includes(def)) {
throw `'${def}' should have been removed from core bundle, but was still there.\n` +
`See output at ${outputPath}.`;
}
}
1 change: 1 addition & 0 deletions packages/compiler-cli/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ export * from './src/transformers/api';
export * from './src/transformers/entry_points';

export * from './src/perform_compile';
export * from './src/tooling';

// TODO(tbosch): remove this once cli 1.5 is fully released,
// and usages in G3 are changed to `CompilerOptions`.
Expand Down
22 changes: 22 additions & 0 deletions packages/compiler-cli/src/tooling.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
/**
* @license
* Copyright Google Inc. All Rights Reserved.
*
* Use of this source code is governed by an MIT-style license that can be
* found in the LICENSE file at https://angular.io/license
*/

/**
* @module
* @description
* Tooling support helpers.
*/

/**
* Known values for global variables in `@angular/core` that Terser should set using
* https://github.com/terser-js/terser#conditional-compilation
*/
export const GLOBAL_DEFS_FOR_TERSER = {
ngDevMode: false,
ngI18nClosureMode: false,
};
4 changes: 3 additions & 1 deletion packages/core/src/util/ng_dev_mode.ts
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,9 @@ export function ngDevModeResetPerfCounters(): NgDevModePerfCounters {
* The idea is that unless we are doing production build where we explicitly
* set `ngDevMode == false` we should be helping the developer by providing
* as much early warning and errors as possible.
*
* NOTE: changes to the `ngDevMode` name must be synced with `compiler-cli/src/tooling.ts`.
*/
if (typeof global['ngDevMode'] === 'undefined' || global['ngDevMode']) {
if (typeof ngDevMode === 'undefined' || ngDevMode) {
ngDevModeResetPerfCounters();
}
5 changes: 4 additions & 1 deletion packages/core/src/util/ng_i18n_closure_mode.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,10 @@ declare global {
const ngI18nClosureMode: boolean;
}

if (typeof global['ngI18nClosureMode'] === 'undefined') {
/**
* NOTE: changes to the `ngI18nClosureMode` name must be synced with `compiler-cli/src/tooling.ts`.
*/
if (typeof ngI18nClosureMode === 'undefined') {
// Make sure to refer to ngI18nClosureMode as ['ngI18nClosureMode'] for closure.
global['ngI18nClosureMode'] =
// TODO(FW-1250): validate that this actually, you know, works.
Expand Down