-
Notifications
You must be signed in to change notification settings - Fork 6.8k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
build: update size test tool to work with Angular v13 (#23811)
* test: remove unnecessary boostrap module calls in size tests * build: add comment explaining the processing of `.mjs` in esbuild rule Adds a little comment explaining why`.mjs` is processed in the Angular esbuild rule. * build: update size test tool to work with Angular v13 Updates the size test tool to properly run with the Angular v13 compilation pipeline, matching conceptually with what the Angular CLI performs. i.e. running the Angular linker, running the non-deprecated build-optimizer variant (i.e. the Babel plugins). * test: update size-golden to reflect recent compilation pipeline changes
- Loading branch information
1 parent
656320d
commit f7b5497
Showing
10 changed files
with
138 additions
and
84 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,18 +1,18 @@ | ||
cdk/drag-drop/all-directives: 160859 | ||
cdk/drag-drop/basic: 158225 | ||
material-experimental/mdc-chips/basic: 385551 | ||
material-experimental/mdc-form-field/advanced: 417584 | ||
material-experimental/mdc-form-field/basic: 416339 | ||
material/autocomplete/without-optgroup: 392028 | ||
material/button-toggle/standalone: 124412 | ||
material/chips/basic: 320073 | ||
material/datepicker/range-picker/without-form-field: 505044 | ||
material/expansion/without-accordion: 330526 | ||
material/form-field/advanced: 377468 | ||
material/form-field/basic: 376144 | ||
material/list/nav-list: 328072 | ||
material/menu/without-lazy-content: 398590 | ||
material/radio/without-group: 127571 | ||
material/select/basic: 437305 | ||
material/tabs/advanced: 369608 | ||
material/tabs/basic: 368747 | ||
cdk/drag-drop/all-directives: 155091 | ||
cdk/drag-drop/basic: 152522 | ||
material-experimental/mdc-chips/basic: 249660 | ||
material-experimental/mdc-form-field/advanced: 296409 | ||
material-experimental/mdc-form-field/basic: 294855 | ||
material/autocomplete/without-optgroup: 281544 | ||
material/button-toggle/standalone: 186619 | ||
material/chips/basic: 228157 | ||
material/datepicker/range-picker/without-form-field: 398783 | ||
material/expansion/without-accordion: 200184 | ||
material/form-field/advanced: 247973 | ||
material/form-field/basic: 246355 | ||
material/list/nav-list: 194468 | ||
material/menu/without-lazy-content: 286831 | ||
material/radio/without-group: 189803 | ||
material/select/basic: 329893 | ||
material/tabs/advanced: 248653 | ||
material/tabs/basic: 247787 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,90 @@ | ||
/** | ||
* @license | ||
* Copyright Google LLC 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 | ||
*/ | ||
|
||
import babel from '@babel/core'; | ||
import {createEs2015LinkerPlugin} from '@angular/compiler-cli/linker/babel'; | ||
import {ConsoleLogger, NodeJSFileSystem, LogLevel} from '@angular/compiler-cli'; | ||
import {GLOBAL_DEFS_FOR_TERSER_WITH_AOT} from '@angular/compiler-cli/private/tooling'; | ||
import adjustStaticClassMembersPlugin from '@angular-devkit/build-angular/src/babel/plugins/adjust-static-class-members.js'; | ||
import elideAngularMetadataPlugin from '@angular-devkit/build-angular/src/babel/plugins/elide-angular-metadata.js'; | ||
import adjustTypeScriptEnumsPlugin from '@angular-devkit/build-angular/src/babel/plugins/adjust-typescript-enums.js'; | ||
import pureToplevelFunctionsPlugin from '@angular-devkit/build-angular/src/babel/plugins/pure-toplevel-functions.js'; | ||
import fs from 'fs'; | ||
|
||
/** Babel plugin running the Angular linker. */ | ||
const linkerBabelPlugin = createEs2015LinkerPlugin({ | ||
fileSystem: new NodeJSFileSystem(), | ||
logger: new ConsoleLogger(LogLevel.warn), | ||
linkerJitMode: false, | ||
}); | ||
|
||
/** | ||
* ESBuild plugin configuring various optimization Babel plugins. The Babel plugins | ||
* configured as part of this plugin run in the Angular CLI compilation pipeline as well. | ||
*/ | ||
const esbuildBabelOptimizePlugin = { | ||
name: 'ng-babel-optimize-esbuild', | ||
setup: build => { | ||
build.onLoad({filter: /.*/}, async args => { | ||
const filePath = args.path; | ||
const content = await fs.promises.readFile(filePath, 'utf8'); | ||
const plugins = [ | ||
linkerBabelPlugin, | ||
adjustStaticClassMembersPlugin, | ||
elideAngularMetadataPlugin, | ||
adjustTypeScriptEnumsPlugin, | ||
]; | ||
|
||
// All files except for the auto-generated module entry-point are considered side-effect | ||
// free. For these we can add the pure-top level Babel plugin. This matches conceptually | ||
// with what is done in the Angular CLI compilation pipeline, with respect to everything | ||
// in this repo being an official side-effect free APF package. | ||
if (!args.path.includes('autogenerated_module_index.mjs')) { | ||
plugins.push(pureToplevelFunctionsPlugin); | ||
} | ||
|
||
const {code} = await babel.transformAsync(content, { | ||
filename: filePath, | ||
filenameRelative: filePath, | ||
plugins: plugins, | ||
// Sourcemaps are generated inline so that ESBuild can process them. | ||
sourceMaps: 'inline', | ||
compact: false, | ||
}); | ||
|
||
return {contents: code}; | ||
}); | ||
}, | ||
}; | ||
|
||
export default { | ||
// Note: We prefer `.mjs` here as this is the extension used by Angular APF packages. | ||
resolveExtensions: ['.mjs', '.js'], | ||
conditions: ['es2020', 'es2015'], | ||
mainFields: ['fesm2020', 'es2020', 'es2015', 'module'], | ||
format: 'iife', | ||
// The majority of these options match with the ones the CLI sets: | ||
// https://github.com/angular/angular-cli/blob/0d76bf04bca6e083865972b5398a32bbe9396e14/packages/angular_devkit/build_angular/src/webpack/plugins/javascript-optimizer-worker.ts#L133. | ||
treeShaking: true, | ||
minifyIdentifiers: true, | ||
minifySyntax: true, | ||
minifyWhitespace: false, | ||
pure: ['forwardRef'], | ||
legalComments: 'none', | ||
// ESBuild requires the `define` option to take a string-based dictionary. | ||
define: convertObjectToStringDictionary(GLOBAL_DEFS_FOR_TERSER_WITH_AOT), | ||
plugins: [esbuildBabelOptimizePlugin], | ||
}; | ||
|
||
/** Converts an object to a string dictionary. */ | ||
function convertObjectToStringDictionary(value) { | ||
return Object.entries(value).reduce((result, [propName, value]) => { | ||
result[propName] = String(value); | ||
return result; | ||
}, {}); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,17 +1,12 @@ | ||
{ | ||
"output": { | ||
"ecma": "es2015", | ||
"comments": false | ||
}, | ||
"ecma": "es2020", | ||
"compress": { | ||
"global_defs": { | ||
"ngDevMode": false, | ||
"ngI18nClosureMode": false, | ||
"ngJitMode": false | ||
}, | ||
"passes": 3, | ||
"passes": 2, | ||
"pure_getters": true | ||
}, | ||
"toplevel": true, | ||
"mangle": true | ||
"format": { | ||
"ascii_only": true, | ||
"wrap_func_args": false | ||
}, | ||
"mangle": false | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters