@@ -15,6 +15,7 @@ const gulpRollup = require('gulp-better-rollup');
15
15
const gulpMinifyCss = require ( 'gulp-clean-css' ) ;
16
16
const gulpMinifyHtml = require ( 'gulp-htmlmin' ) ;
17
17
const gulpIf = require ( 'gulp-if' ) ;
18
+ const merge2 = require ( 'merge2' ) ;
18
19
19
20
20
21
// NOTE: there are two build "modes" in this file, based on which tsconfig is used.
@@ -24,9 +25,9 @@ const gulpIf = require('gulp-if');
24
25
// When `tsconfig-spec.json` is used, we are outputting CommonJS modules. This is used
25
26
// for unit tests (karma).
26
27
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' ) ;
30
31
31
32
/** [Watch task] Rebuilds (ESM output) whenever ts, scss, or html sources change. */
32
33
task ( ':watch:components' , ( ) => {
@@ -36,11 +37,11 @@ task(':watch:components', () => {
36
37
} ) ;
37
38
38
39
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 ) ) ;
41
42
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 ) ) ;
44
45
45
46
/** Copies assets (html, markdown) to build output. */
46
47
task ( ':build:components:assets' , copyTask ( [
@@ -61,53 +62,13 @@ task(':build:components:scss', sassBuildTask(DIST_COMPONENTS_ROOT, COMPONENTS_DI
61
62
62
63
/** Builds the UMD bundle for all of Angular Material. */
63
64
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' ) ) ;
98
67
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' ) ) ;
108
70
109
- return src ( path . join ( DIST_COMPONENTS_ROOT , 'index.js' ) )
110
- . pipe ( gulpRollup ( rollupOptions , rollupGenerateOptions ) )
71
+ return merge2 ( esBundle , umdBundle )
111
72
. pipe ( dest ( path . join ( DIST_COMPONENTS_ROOT , 'bundles' ) ) ) ;
112
73
} ) ;
113
74
@@ -135,5 +96,55 @@ task('build:components:release', sequenceTask(
135
96
136
97
/** Generates metadata.json files for all of the components. */
137
98
task ( ':build:components:ngc' , [ 'build:components:release' ] , execNodeTask (
138
- '@angular/compiler-cli' , 'ngc' , [ '-p' , tsconfigPath ]
99
+ '@angular/compiler-cli' , 'ngc' , [ '-p' , tsconfigES6 ]
139
100
) ) ;
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