Skip to content

Commit c02284e

Browse files
committed
build: import tslib instead of letting tsc generate helpers
1 parent 0e24345 commit c02284e

11 files changed

+38
-2
lines changed

package.json

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@
3535
"core-js": "^2.4.1",
3636
"rxjs": "^5.0.1",
3737
"systemjs": "0.19.43",
38+
"tslib": "^1.7.1",
3839
"zone.js": "^0.8.4"
3940
},
4041
"devDependencies": {
@@ -104,6 +105,7 @@
104105
"request": "^2.81.0",
105106
"resolve-bin": "^0.4.0",
106107
"rollup": "^0.41.6",
108+
"rollup-plugin-node-resolve": "^3.0.0",
107109
"run-sequence": "^1.2.2",
108110
"scss-bundle": "^2.0.1-beta.7",
109111
"selenium-webdriver": "^3.4.0",

src/cdk/package.json

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,5 +26,8 @@
2626
"peerDependencies": {
2727
"@angular/core": "^4.0.0",
2828
"@angular/common": "^4.0.0"
29+
},
30+
"dependencies": {
31+
"tslib": "^1.7.1"
2932
}
3033
}

src/cdk/tsconfig-build.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
"declaration": true,
77
"stripInternal": false,
88
"experimentalDecorators": true,
9+
"importHelpers": true,
910
"module": "es2015",
1011
"moduleResolution": "node",
1112
"outDir": "../../dist/packages/cdk",

src/cdk/tsconfig-tests.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
{
55
"extends": "./tsconfig-build",
66
"compilerOptions": {
7+
"importHelpers": false,
78
"module": "commonjs",
89
"target": "es5",
910
"types": ["jasmine"],

src/lib/package.json

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,5 +24,8 @@
2424
"peerDependencies": {
2525
"@angular/core": "^4.0.0",
2626
"@angular/common": "^4.0.0"
27+
},
28+
"dependencies": {
29+
"tslib": "^1.7.1"
2730
}
2831
}

src/lib/tsconfig-build.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
"declaration": true,
66
"stripInternal": false,
77
"experimentalDecorators": true,
8+
"importHelpers": true,
89
"module": "es2015",
910
"moduleResolution": "node",
1011
"outDir": "../../dist/packages/material",

src/lib/tsconfig-tests.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
{
55
"extends": "./tsconfig-build",
66
"compilerOptions": {
7+
"importHelpers": false,
78
"module": "commonjs",
89
"target": "es5",
910
"types": ["jasmine"],

src/material-examples/package.json

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,5 +26,8 @@
2626
"@angular/core": "^4.0.0",
2727
"@angular/common": "^4.0.0",
2828
"@angular/http": "^4.0.0"
29+
},
30+
"dependencies": {
31+
"tslib": "^1.7.1"
2932
}
3033
}

src/material-examples/tsconfig-build.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
"declaration": true,
66
"stripInternal": false,
77
"experimentalDecorators": true,
8+
"importHelpers": true,
89
"module": "es2015",
910
"moduleResolution": "node",
1011
"outDir": "../../dist/packages/material-examples",

tools/gulp/packaging/build-bundles.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@ export async function buildPackageBundles(entryFile: string, packageName: string
3232

3333
// Downlevel FESM-2015 file to ES5.
3434
transpileFile(fesm2015File, fesm2014File, {
35+
importHelpers: true,
3536
target: ScriptTarget.ES5,
3637
module: ModuleKind.ES2015,
3738
allowJs: true

tools/gulp/packaging/rollup-helpers.ts

Lines changed: 21 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,13 @@ import {LICENSE_BANNER} from '../constants';
22

33
// There are no type definitions available for these imports.
44
const rollup = require('rollup');
5+
const rollupNodeResolutionPlugin = require('rollup-plugin-node-resolve');
56

67
const ROLLUP_GLOBALS = {
8+
// Import tslib rather than having TypeScript output its helpers multiple times.
9+
// See https://github.com/Microsoft/tslib
10+
'tslib': 'tslib',
11+
712
// Angular dependencies
813
'@angular/animations': 'ng.animations',
914
'@angular/core': 'ng.core',
@@ -50,10 +55,10 @@ export type BundleConfig = {
5055

5156
/** Creates a rollup bundle of a specified JavaScript file.*/
5257
export function createRollupBundle(config: BundleConfig): Promise<any> {
53-
const bundleOptions = {
58+
const bundleOptions: any = {
5459
context: 'this',
5560
external: Object.keys(ROLLUP_GLOBALS),
56-
entry: config.entry
61+
entry: config.entry,
5762
};
5863

5964
const writeOptions = {
@@ -67,5 +72,19 @@ export function createRollupBundle(config: BundleConfig): Promise<any> {
6772
sourceMap: true
6873
};
6974

75+
// When creating a UMD, we want to exclude tslib from the `external` and `globals` bundle options
76+
// so that it is inlined into the bundle.
77+
if (config.format === 'umd') {
78+
bundleOptions.plugins = [rollupNodeResolutionPlugin()];
79+
80+
// Clone ROLLUP_GLOBALS so we don't accidentally modify it.
81+
bundleOptions.globals = Object.assign({}, ROLLUP_GLOBALS);
82+
delete bundleOptions.globals.tslib;
83+
84+
const external = Object.keys(ROLLUP_GLOBALS);
85+
external.splice(external.indexOf('tslib'), 1);
86+
bundleOptions.external = external;
87+
}
88+
7089
return rollup.rollup(bundleOptions).then((bundle: any) => bundle.write(writeOptions));
7190
}

0 commit comments

Comments
 (0)