@@ -15,6 +15,7 @@ const gulpRollup = require('gulp-better-rollup');
1515const gulpMinifyCss = require ( 'gulp-clean-css' ) ;
1616const gulpMinifyHtml = require ( 'gulp-htmlmin' ) ;
1717const 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. */
3233task ( ':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. */
4647task ( ':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. */
6364task ( ':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. */
13798task ( ':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+ }
0 commit comments