build: import tslib instead of letting tsc generate helpers (#4787)

This commit is contained in:
Jeremy Elbourn
2017-05-25 13:36:02 -07:00
committed by tinayuangao
parent 0e2434568d
commit e3b2587294
11 changed files with 34 additions and 2 deletions
+2
View File
@@ -35,6 +35,7 @@
"core-js": "^2.4.1",
"rxjs": "^5.0.1",
"systemjs": "0.19.43",
"tslib": "^1.7.1",
"zone.js": "^0.8.4"
},
"devDependencies": {
@@ -104,6 +105,7 @@
"request": "^2.81.0",
"resolve-bin": "^0.4.0",
"rollup": "^0.41.6",
"rollup-plugin-node-resolve": "^3.0.0",
"run-sequence": "^1.2.2",
"scss-bundle": "^2.0.1-beta.7",
"selenium-webdriver": "^3.4.0",
+3
View File
@@ -26,5 +26,8 @@
"peerDependencies": {
"@angular/core": "^4.0.0",
"@angular/common": "^4.0.0"
},
"dependencies": {
"tslib": "^1.7.1"
}
}
+1
View File
@@ -6,6 +6,7 @@
"declaration": true,
"stripInternal": false,
"experimentalDecorators": true,
"importHelpers": true,
"module": "es2015",
"moduleResolution": "node",
"outDir": "../../dist/packages/cdk",
+1
View File
@@ -4,6 +4,7 @@
{
"extends": "./tsconfig-build",
"compilerOptions": {
"importHelpers": false,
"module": "commonjs",
"target": "es5",
"types": ["jasmine"],
+3
View File
@@ -24,5 +24,8 @@
"peerDependencies": {
"@angular/core": "^4.0.0",
"@angular/common": "^4.0.0"
},
"dependencies": {
"tslib": "^1.7.1"
}
}
+1
View File
@@ -5,6 +5,7 @@
"declaration": true,
"stripInternal": false,
"experimentalDecorators": true,
"importHelpers": true,
"module": "es2015",
"moduleResolution": "node",
"outDir": "../../dist/packages/material",
+1
View File
@@ -4,6 +4,7 @@
{
"extends": "./tsconfig-build",
"compilerOptions": {
"importHelpers": false,
"module": "commonjs",
"target": "es5",
"types": ["jasmine"],
+3
View File
@@ -26,5 +26,8 @@
"@angular/core": "^4.0.0",
"@angular/common": "^4.0.0",
"@angular/http": "^4.0.0"
},
"dependencies": {
"tslib": "^1.7.1"
}
}
@@ -5,6 +5,7 @@
"declaration": true,
"stripInternal": false,
"experimentalDecorators": true,
"importHelpers": true,
"module": "es2015",
"moduleResolution": "node",
"outDir": "../../dist/packages/material-examples",
+1
View File
@@ -32,6 +32,7 @@ export async function buildPackageBundles(entryFile: string, packageName: string
// Downlevel FESM-2015 file to ES5.
transpileFile(fesm2015File, fesm2014File, {
importHelpers: true,
target: ScriptTarget.ES5,
module: ModuleKind.ES2015,
allowJs: true
+17 -2
View File
@@ -2,8 +2,13 @@ import {LICENSE_BANNER} from '../constants';
// There are no type definitions available for these imports.
const rollup = require('rollup');
const rollupNodeResolutionPlugin = require('rollup-plugin-node-resolve');
const ROLLUP_GLOBALS = {
// Import tslib rather than having TypeScript output its helpers multiple times.
// See https://github.com/Microsoft/tslib
'tslib': 'tslib',
// Angular dependencies
'@angular/animations': 'ng.animations',
'@angular/core': 'ng.core',
@@ -50,10 +55,10 @@ export type BundleConfig = {
/** Creates a rollup bundle of a specified JavaScript file.*/
export function createRollupBundle(config: BundleConfig): Promise<any> {
const bundleOptions = {
const bundleOptions: any = {
context: 'this',
external: Object.keys(ROLLUP_GLOBALS),
entry: config.entry
entry: config.entry,
};
const writeOptions = {
@@ -67,5 +72,15 @@ export function createRollupBundle(config: BundleConfig): Promise<any> {
sourceMap: true
};
// When creating a UMD, we want to exclude tslib from the `external` bundle option so that it
// is inlined into the bundle.
if (config.format === 'umd') {
bundleOptions.plugins = [rollupNodeResolutionPlugin()];
const external = Object.keys(ROLLUP_GLOBALS);
external.splice(external.indexOf('tslib'), 1);
bundleOptions.external = external;
}
return rollup.rollup(bundleOptions).then((bundle: any) => bundle.write(writeOptions));
}