perf: distrubute smaller bundled code and include es2015 bundle

TypeScript compiler will now build to ES2015 code and modules. Babili is used to minify ES2015
code, providing an initial optimization that we couldn't previously get just from Uglify. Uses
Babel to convert ES2015 to UMD/ES5 code, and Uglify to minimize the output.
This commit is contained in:
Jason Aden
2017-01-27 17:39:48 -08:00
committed by Igor Minar
parent 738d93caf7
commit de795ea233
175 changed files with 2515 additions and 1246 deletions

View File

@ -79,6 +79,7 @@ export class MetadataBundler {
private metadataCache = new Map<string, ModuleMetadata>();
private exports = new Map<string, Symbol[]>();
private rootModule: string;
private exported: Set<Symbol>;
constructor(
private root: string, private importAs: string|undefined, private host: MetadataBundlerHost) {
@ -191,16 +192,18 @@ export class MetadataBundler {
*/
private canonicalizeSymbols(exportedSymbols: Symbol[]) {
const symbols = Array.from(this.symbolMap.values());
const exported = new Set(exportedSymbols);
symbols.forEach(symbol => {
const rootExport = getRootExport(symbol);
const declaration = getSymbolDeclaration(symbol);
const isPrivate = !exported.has(rootExport);
const canonicalSymbol = isPrivate ? declaration : rootExport;
symbol.isPrivate = isPrivate;
symbol.declaration = declaration;
symbol.canonicalSymbol = canonicalSymbol;
});
this.exported = new Set(exportedSymbols);;
symbols.forEach(this.canonicalizeSymbol, this);
}
private canonicalizeSymbol(symbol: Symbol) {
const rootExport = getRootExport(symbol);
const declaration = getSymbolDeclaration(symbol);
const isPrivate = !this.exported.has(rootExport);
const canonicalSymbol = isPrivate ? declaration : rootExport;
symbol.isPrivate = isPrivate;
symbol.declaration = declaration;
symbol.canonicalSymbol = canonicalSymbol;
}
private getEntries(exportedSymbols: Symbol[]): BundleEntries {
@ -487,14 +490,11 @@ export class MetadataBundler {
}
private canonicalSymbolOf(module: string, name: string): Symbol {
// Ensure the module has been seen.
this.exportAll(module);
const symbol = this.symbolOf(module, name);
if (!symbol.canonicalSymbol) {
// If we get a symbol after canonical symbols have been assigned it must be a private
// symbol so treat it as one.
symbol.declaration = symbol;
symbol.canonicalSymbol = symbol;
symbol.isPrivate = true;
this.convertSymbol(symbol);
this.canonicalizeSymbol(symbol);
}
return symbol;
}

View File

@ -29,7 +29,7 @@ export type CodegenExtension =
export function main(
project: string | VinylFile, cliOptions: CliOptions, codegen?: CodegenExtension,
options?: ts.CompilerOptions): Promise<any> {
options?: ts.CompilerOptions, skipImportRename?: boolean): Promise<any> {
try {
let projectDir = project;
// project is vinyl like file object
@ -118,7 +118,7 @@ export function main(
const tsickleCompilerHostOptions: tsickle.Options = {
googmodule: false,
untyped: true,
convertIndexImportShorthand:
convertIndexImportShorthand: !skipImportRename &&
ngOptions.target === ts.ScriptTarget.ES2015, // This covers ES6 too
};
@ -173,13 +173,19 @@ export function main(
// CLI entry point
if (require.main === module) {
const args = process.argv.slice(2);
let args = process.argv.slice(2);
let idx = args.indexOf('--skipImportRename');
let skipImportRename = false;
if (idx !== -1) {
args.splice(idx, 1);
skipImportRename = true;
}
let {options, fileNames, errors} = (ts as any).parseCommandLine(args);
check(errors);
const project = options.project || '.';
// TODO(alexeagle): command line should be TSC-compatible, remove "CliOptions" here
const cliOptions = new CliOptions(require('minimist')(args));
main(project, cliOptions, null, options)
main(project, cliOptions, null, options, skipImportRename)
.then((exitCode: any) => process.exit(exitCode))
.catch((e: any) => {
console.error(e.stack);