diff --git a/package.json b/package.json index 1c84538eb975..1f2e7c5491da 100644 --- a/package.json +++ b/package.json @@ -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", diff --git a/src/cdk/package.json b/src/cdk/package.json index 527a67d80882..c69eadbb69bf 100644 --- a/src/cdk/package.json +++ b/src/cdk/package.json @@ -26,5 +26,8 @@ "peerDependencies": { "@angular/core": "^4.0.0", "@angular/common": "^4.0.0" + }, + "dependencies": { + "tslib": "^1.7.1" } } diff --git a/src/cdk/tsconfig-build.json b/src/cdk/tsconfig-build.json index 1bd184156235..6f9147eba187 100644 --- a/src/cdk/tsconfig-build.json +++ b/src/cdk/tsconfig-build.json @@ -6,6 +6,7 @@ "declaration": true, "stripInternal": false, "experimentalDecorators": true, + "importHelpers": true, "module": "es2015", "moduleResolution": "node", "outDir": "../../dist/packages/cdk", diff --git a/src/cdk/tsconfig-tests.json b/src/cdk/tsconfig-tests.json index b4331fcd5fed..95e7f82d42ef 100644 --- a/src/cdk/tsconfig-tests.json +++ b/src/cdk/tsconfig-tests.json @@ -4,6 +4,7 @@ { "extends": "./tsconfig-build", "compilerOptions": { + "importHelpers": false, "module": "commonjs", "target": "es5", "types": ["jasmine"], diff --git a/src/lib/package.json b/src/lib/package.json index 885abbc6218a..8dc98c84ba44 100644 --- a/src/lib/package.json +++ b/src/lib/package.json @@ -24,5 +24,8 @@ "peerDependencies": { "@angular/core": "^4.0.0", "@angular/common": "^4.0.0" + }, + "dependencies": { + "tslib": "^1.7.1" } } diff --git a/src/lib/tsconfig-build.json b/src/lib/tsconfig-build.json index a8ec71d3c30b..5efd7f75f478 100644 --- a/src/lib/tsconfig-build.json +++ b/src/lib/tsconfig-build.json @@ -5,6 +5,7 @@ "declaration": true, "stripInternal": false, "experimentalDecorators": true, + "importHelpers": true, "module": "es2015", "moduleResolution": "node", "outDir": "../../dist/packages/material", diff --git a/src/lib/tsconfig-tests.json b/src/lib/tsconfig-tests.json index 61f25f94361c..4c289bb0a2aa 100644 --- a/src/lib/tsconfig-tests.json +++ b/src/lib/tsconfig-tests.json @@ -4,6 +4,7 @@ { "extends": "./tsconfig-build", "compilerOptions": { + "importHelpers": false, "module": "commonjs", "target": "es5", "types": ["jasmine"], diff --git a/src/material-examples/package.json b/src/material-examples/package.json index ad8a5041849f..5ad0f1f5a52f 100644 --- a/src/material-examples/package.json +++ b/src/material-examples/package.json @@ -26,5 +26,8 @@ "@angular/core": "^4.0.0", "@angular/common": "^4.0.0", "@angular/http": "^4.0.0" + }, + "dependencies": { + "tslib": "^1.7.1" } } diff --git a/src/material-examples/tsconfig-build.json b/src/material-examples/tsconfig-build.json index 5c9b9d3bc238..275f76fe1c53 100644 --- a/src/material-examples/tsconfig-build.json +++ b/src/material-examples/tsconfig-build.json @@ -5,6 +5,7 @@ "declaration": true, "stripInternal": false, "experimentalDecorators": true, + "importHelpers": true, "module": "es2015", "moduleResolution": "node", "outDir": "../../dist/packages/material-examples", diff --git a/tools/gulp/packaging/build-bundles.ts b/tools/gulp/packaging/build-bundles.ts index 015afaa0b282..3c6d2821404a 100644 --- a/tools/gulp/packaging/build-bundles.ts +++ b/tools/gulp/packaging/build-bundles.ts @@ -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 diff --git a/tools/gulp/packaging/rollup-helpers.ts b/tools/gulp/packaging/rollup-helpers.ts index ab1c10b8e94e..aff500a276a8 100644 --- a/tools/gulp/packaging/rollup-helpers.ts +++ b/tools/gulp/packaging/rollup-helpers.ts @@ -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 { - 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 { 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)); }