Skip to content

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

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
May 25, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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": {
Expand Down Expand Up @@ -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",
Expand Down
3 changes: 3 additions & 0 deletions src/cdk/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -26,5 +26,8 @@
"peerDependencies": {
"@angular/core": "^4.0.0",
"@angular/common": "^4.0.0"
},
"dependencies": {
"tslib": "^1.7.1"
}
}
1 change: 1 addition & 0 deletions src/cdk/tsconfig-build.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
"declaration": true,
"stripInternal": false,
"experimentalDecorators": true,
"importHelpers": true,
"module": "es2015",
"moduleResolution": "node",
"outDir": "../../dist/packages/cdk",
Expand Down
1 change: 1 addition & 0 deletions src/cdk/tsconfig-tests.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
{
"extends": "./tsconfig-build",
"compilerOptions": {
"importHelpers": false,
"module": "commonjs",
"target": "es5",
"types": ["jasmine"],
Expand Down
3 changes: 3 additions & 0 deletions src/lib/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -24,5 +24,8 @@
"peerDependencies": {
"@angular/core": "^4.0.0",
"@angular/common": "^4.0.0"
},
"dependencies": {
"tslib": "^1.7.1"
}
}
1 change: 1 addition & 0 deletions src/lib/tsconfig-build.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
"declaration": true,
"stripInternal": false,
"experimentalDecorators": true,
"importHelpers": true,
"module": "es2015",
"moduleResolution": "node",
"outDir": "../../dist/packages/material",
Expand Down
1 change: 1 addition & 0 deletions src/lib/tsconfig-tests.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
{
"extends": "./tsconfig-build",
"compilerOptions": {
"importHelpers": false,
"module": "commonjs",
"target": "es5",
"types": ["jasmine"],
Expand Down
3 changes: 3 additions & 0 deletions src/material-examples/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -26,5 +26,8 @@
"@angular/core": "^4.0.0",
"@angular/common": "^4.0.0",
"@angular/http": "^4.0.0"
},
"dependencies": {
"tslib": "^1.7.1"
}
}
1 change: 1 addition & 0 deletions src/material-examples/tsconfig-build.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
"declaration": true,
"stripInternal": false,
"experimentalDecorators": true,
"importHelpers": true,
"module": "es2015",
"moduleResolution": "node",
"outDir": "../../dist/packages/material-examples",
Expand Down
1 change: 1 addition & 0 deletions tools/gulp/packaging/build-bundles.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
19 changes: 17 additions & 2 deletions tools/gulp/packaging/rollup-helpers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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',
Expand Down Expand Up @@ -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 = {
Expand All @@ -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));
}