Skip to content

Commit b3e973e

Browse files
committed
build: ship esm bundle
* Now ships a Flat / ESM bundle (similar as for Angular 4+ releases) * Links the pkg `module` to the new ESM bundle. * For a consistent and clear project-structure there will be `tsconfig-es6` or `tsconfig-es5` files. References #3316
1 parent 02f4bc3 commit b3e973e

File tree

9 files changed

+102
-57
lines changed

9 files changed

+102
-57
lines changed
File renamed without changes.
File renamed without changes.

src/lib/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
"version": "2.0.0-beta.2",
44
"description": "Angular Material",
55
"main": "./bundles/material.umd.js",
6-
"module": "./index.js",
6+
"module": "./bundles/material.js",
77
"typings": "./index.d.ts",
88
"repository": {
99
"type": "git",
File renamed without changes.

src/lib/tsconfig-srcs.json renamed to src/lib/tsconfig-es6.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111
"outDir": "../../dist/@angular/material",
1212
"rootDir": ".",
1313
"sourceMap": true,
14-
"target": "es5",
14+
"target": "es6",
1515
"inlineSources": true,
1616
"stripInternal": false,
1717
"typeRoots": [

src/tsconfig.json

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
/**
2+
* Source TSConfig file that is just used for IDE completion and linting.
3+
* Each package inside of the sources includes their own tsconfig files.
4+
**/
5+
{
6+
"compilerOptions": {
7+
"emitDecoratorMetadata": true,
8+
"experimentalDecorators": true,
9+
"lib": ["es6", "es2015", "dom"],
10+
"module": "commonjs",
11+
"moduleResolution": "node",
12+
"noEmitOnError": true,
13+
"noImplicitAny": true,
14+
"outDir": "../../dist/all",
15+
"rootDir": ".",
16+
"target": "es5",
17+
"paths": {
18+
"@angular/material": [
19+
"../dist/@angular/material"
20+
]
21+
},
22+
"typeRoots": [
23+
"../node_modules/@types/!(node)"
24+
],
25+
"types": [
26+
"jasmine",
27+
"rx/rx.all"
28+
]
29+
}
30+
}

tools/gulp/tasks/components.ts

Lines changed: 64 additions & 53 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ const gulpRollup = require('gulp-better-rollup');
1515
const gulpMinifyCss = require('gulp-clean-css');
1616
const gulpMinifyHtml = require('gulp-htmlmin');
1717
const gulpIf = require('gulp-if');
18+
const merge2 = require('merge2');
1819

1920

2021
// NOTE: there are two build "modes" in this file, based on which tsconfig is used.
@@ -24,9 +25,9 @@ const gulpIf = require('gulp-if');
2425
// When `tsconfig-spec.json` is used, we are outputting CommonJS modules. This is used
2526
// for unit tests (karma).
2627

27-
/** Path to the tsconfig used for ESM output. */
28-
const tsconfigPath = path.relative(PROJECT_ROOT, path.join(COMPONENTS_DIR, 'tsconfig-srcs.json'));
29-
28+
/** Path to the different tsconfig files. */
29+
const tsconfigES6 = path.join(COMPONENTS_DIR, 'tsconfig-es6.json');
30+
const tsconfigES5 = path.join(COMPONENTS_DIR, 'tsconfig-es5.json');
3031

3132
/** [Watch task] Rebuilds (ESM output) whenever ts, scss, or html sources change. */
3233
task(':watch:components', () => {
@@ -36,11 +37,11 @@ task(':watch:components', () => {
3637
});
3738

3839

39-
/** Builds component typescript only (ESM output). */
40-
task(':build:components:ts', tsBuildTask(path.join(COMPONENTS_DIR, 'tsconfig-srcs.json')));
40+
/** Builds component typescript only (ES6 output). */
41+
task(':build:components:ts', tsBuildTask(tsconfigES6));
4142

42-
/** Builds components typescript for tests (CJS output). */
43-
task(':build:components:spec', tsBuildTask(COMPONENTS_DIR));
43+
/** Builds components typescript for tests (ES5 output). */
44+
task(':build:components:spec', tsBuildTask(tsconfigES5));
4445

4546
/** Copies assets (html, markdown) to build output. */
4647
task(':build:components:assets', copyTask([
@@ -61,53 +62,13 @@ task(':build:components:scss', sassBuildTask(DIST_COMPONENTS_ROOT, COMPONENTS_DI
6162

6263
/** Builds the UMD bundle for all of Angular Material. */
6364
task(':build:components:rollup', () => {
64-
const globals: {[name: string]: string} = {
65-
// Angular dependencies
66-
'@angular/core': 'ng.core',
67-
'@angular/common': 'ng.common',
68-
'@angular/forms': 'ng.forms',
69-
'@angular/http': 'ng.http',
70-
'@angular/platform-browser': 'ng.platformBrowser',
71-
'@angular/platform-browser-dynamic': 'ng.platformBrowserDynamic',
72-
73-
// Rxjs dependencies
74-
'rxjs/Subject': 'Rx',
75-
'rxjs/add/observable/fromEvent': 'Rx.Observable',
76-
'rxjs/add/observable/forkJoin': 'Rx.Observable',
77-
'rxjs/add/observable/of': 'Rx.Observable',
78-
'rxjs/add/observable/merge': 'Rx.Observable',
79-
'rxjs/add/observable/throw': 'Rx.Observable',
80-
'rxjs/add/operator/auditTime': 'Rx.Observable.prototype',
81-
'rxjs/add/operator/toPromise': 'Rx.Observable.prototype',
82-
'rxjs/add/operator/map': 'Rx.Observable.prototype',
83-
'rxjs/add/operator/filter': 'Rx.Observable.prototype',
84-
'rxjs/add/operator/do': 'Rx.Observable.prototype',
85-
'rxjs/add/operator/share': 'Rx.Observable.prototype',
86-
'rxjs/add/operator/finally': 'Rx.Observable.prototype',
87-
'rxjs/add/operator/catch': 'Rx.Observable.prototype',
88-
'rxjs/add/operator/first': 'Rx.Observable.prototype',
89-
'rxjs/add/operator/startWith': 'Rx.Observable.prototype',
90-
'rxjs/add/operator/switchMap': 'Rx.Observable.prototype',
91-
'rxjs/Observable': 'Rx'
92-
};
93-
94-
const rollupOptions = {
95-
context: 'this',
96-
external: Object.keys(globals)
97-
};
65+
let esBundle = src(path.join(DIST_COMPONENTS_ROOT, 'index.js'))
66+
.pipe(createRollupBundle('es', 'material.js'));
9867

99-
const rollupGenerateOptions = {
100-
// Keep the moduleId empty because we don't want to force developers to a specific moduleId.
101-
moduleId: '',
102-
moduleName: 'ng.material',
103-
format: 'umd',
104-
globals,
105-
banner: LICENSE_BANNER,
106-
dest: 'material.umd.js'
107-
};
68+
let umdBundle = src(path.join(DIST_COMPONENTS_ROOT, 'index.js'))
69+
.pipe(createRollupBundle('umd', 'material.umd.js'));
10870

109-
return src(path.join(DIST_COMPONENTS_ROOT, 'index.js'))
110-
.pipe(gulpRollup(rollupOptions, rollupGenerateOptions))
71+
return merge2(esBundle, umdBundle)
11172
.pipe(dest(path.join(DIST_COMPONENTS_ROOT, 'bundles')));
11273
});
11374

@@ -135,5 +96,55 @@ task('build:components:release', sequenceTask(
13596

13697
/** Generates metadata.json files for all of the components. */
13798
task(':build:components:ngc', ['build:components:release'], execNodeTask(
138-
'@angular/compiler-cli', 'ngc', ['-p', tsconfigPath]
99+
'@angular/compiler-cli', 'ngc', ['-p', tsconfigES6]
139100
));
101+
102+
const ROLLUP_GLOBALS = {
103+
// Angular dependencies
104+
'@angular/core': 'ng.core',
105+
'@angular/common': 'ng.common',
106+
'@angular/forms': 'ng.forms',
107+
'@angular/http': 'ng.http',
108+
'@angular/platform-browser': 'ng.platformBrowser',
109+
'@angular/platform-browser-dynamic': 'ng.platformBrowserDynamic',
110+
111+
// Rxjs dependencies
112+
'rxjs/Subject': 'Rx',
113+
'rxjs/add/observable/fromEvent': 'Rx.Observable',
114+
'rxjs/add/observable/forkJoin': 'Rx.Observable',
115+
'rxjs/add/observable/of': 'Rx.Observable',
116+
'rxjs/add/observable/merge': 'Rx.Observable',
117+
'rxjs/add/observable/throw': 'Rx.Observable',
118+
'rxjs/add/operator/auditTime': 'Rx.Observable.prototype',
119+
'rxjs/add/operator/toPromise': 'Rx.Observable.prototype',
120+
'rxjs/add/operator/map': 'Rx.Observable.prototype',
121+
'rxjs/add/operator/filter': 'Rx.Observable.prototype',
122+
'rxjs/add/operator/do': 'Rx.Observable.prototype',
123+
'rxjs/add/operator/share': 'Rx.Observable.prototype',
124+
'rxjs/add/operator/finally': 'Rx.Observable.prototype',
125+
'rxjs/add/operator/catch': 'Rx.Observable.prototype',
126+
'rxjs/add/operator/first': 'Rx.Observable.prototype',
127+
'rxjs/add/operator/startWith': 'Rx.Observable.prototype',
128+
'rxjs/add/operator/switchMap': 'Rx.Observable.prototype',
129+
'rxjs/Observable': 'Rx'
130+
};
131+
132+
/** Creates a rollup bundles of the Material components.*/
133+
function createRollupBundle(format: string, outFile: string) {
134+
let rollupOptions = {
135+
context: 'this',
136+
external: Object.keys(ROLLUP_GLOBALS)
137+
};
138+
139+
let rollupGenerateOptions = {
140+
// Keep the moduleId empty because we don't want to force developers to a specific moduleId.
141+
moduleId: '',
142+
moduleName: 'ng.material',
143+
banner: LICENSE_BANNER,
144+
format: format,
145+
dest: outFile,
146+
globals: ROLLUP_GLOBALS,
147+
};
148+
149+
return gulpRollup(rollupOptions, rollupGenerateOptions);
150+
}

tools/gulp/tasks/development.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,9 +17,11 @@ task(':watch:devapp', () => {
1717
watch(path.join(appDir, '**/*.html'), [':build:devapp:assets', triggerLivereload]);
1818
});
1919

20+
/** Path to the demo-app tsconfig file. */
21+
const tsconfigES5 = path.join(appDir, 'tsconfig-es5.json');
2022

2123
task(':build:devapp:vendor', vendorTask());
22-
task(':build:devapp:ts', tsBuildTask(appDir));
24+
task(':build:devapp:ts', tsBuildTask(tsconfigES5));
2325
task(':build:devapp:scss', sassBuildTask(outDir, appDir));
2426
task(':build:devapp:assets', copyTask(appDir, outDir));
2527
task('build:devapp', buildAppTask('devapp'));

tools/gulp/tasks/e2e.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,8 @@ const appDir = path.join(SOURCE_ROOT, 'e2e-app');
1414
const outDir = DIST_ROOT;
1515
const PROTRACTOR_CONFIG_PATH = path.join(PROJECT_ROOT, 'test/protractor.conf.js');
1616

17+
const tsconfigES5 = path.join(appDir, 'tsconfig-es5.json');
18+
1719
task(':watch:e2eapp', () => {
1820
watch(path.join(appDir, '**/*.ts'), [':build:e2eapp:ts']);
1921
watch(path.join(appDir, '**/*.html'), [':build:e2eapp:assets']);
@@ -23,7 +25,7 @@ task(':watch:e2eapp', () => {
2325
task(':build:e2eapp:vendor', vendorTask());
2426

2527
/** Builds e2e app ts to js. */
26-
task(':build:e2eapp:ts', tsBuildTask(appDir));
28+
task(':build:e2eapp:ts', tsBuildTask(tsconfigES5));
2729

2830
/** Copies e2e app assets (html, css) to build output. */
2931
task(':build:e2eapp:assets', copyTask(appDir, outDir));

0 commit comments

Comments
 (0)