Skip to content

Commit 965cd7a

Browse files
devversionjelbourn
authored andcommitted
chore: move umd bundles to bundles directory (#2316)
* Moves the generated `.umd` files to the `bundles/` directory (as @angular/core) * Uses a gulp plugin for rollup because its more clear and also allows us to easily minify & create sourcemaps in the future
1 parent 3847766 commit 965cd7a

File tree

4 files changed

+19
-33
lines changed

4 files changed

+19
-33
lines changed

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -66,6 +66,7 @@
6666
"glob": "^6.0.4",
6767
"gulp": "^3.9.1",
6868
"gulp-autoprefixer": "^3.1.1",
69+
"gulp-better-rollup": "^1.0.2",
6970
"gulp-clean": "^0.3.2",
7071
"gulp-clean-css": "^2.3.0",
7172
"gulp-cli": "^1.2.2",
@@ -91,7 +92,6 @@
9192
"node-sass": "^3.4.2",
9293
"protractor": "^4.0.8",
9394
"resolve-bin": "^0.4.0",
94-
"rollup": "^0.34.13",
9595
"run-sequence": "^1.2.2",
9696
"sass": "^0.5.0",
9797
"selenium-webdriver": "2.53.3",

src/demo-app/system-config.ts

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -17,14 +17,11 @@ System.config({
1717
'@angular/platform-browser': 'vendor/@angular/platform-browser/bundles/platform-browser.umd.js',
1818
'@angular/platform-browser-dynamic':
1919
'vendor/@angular/platform-browser-dynamic/bundles/platform-browser-dynamic.umd.js',
20+
'@angular/material': '@angular/material/bundles/material.umd.js'
2021
},
2122
packages: {
2223
// Thirdparty barrels.
2324
'rxjs': { main: 'index' },
24-
'@angular/material': {
25-
format: 'cjs',
26-
main: 'material.umd.js'
27-
},
2825
// Set the default extension for the root package, because otherwise the demo-app can't
2926
// be built within the production mode. Due to missing file extensions.
3027
'.': {

src/e2e-app/system-config.ts

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -19,14 +19,11 @@ System.config({
1919
'vendor/@angular/platform-browser/bundles/platform-browser-testing.umd.js',
2020
'@angular/platform-browser-dynamic':
2121
'vendor/@angular/platform-browser-dynamic/bundles/platform-browser-dynamic.umd.js',
22+
'@angular/material': '@angular/material/bundles/material.umd.js'
2223
},
2324
packages: {
2425
// Thirdparty barrels.
2526
'rxjs': { main: 'index' },
26-
'@angular/material': {
27-
format: 'cjs',
28-
main: 'material.umd.js'
29-
},
3027
// Set the default extension for the root package, because otherwise the demo-app can't
3128
// be built within the production mode. Due to missing file extensions.
3229
'.': {

tools/gulp/tasks/components.ts

Lines changed: 16 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -5,11 +5,10 @@ import {
55
DIST_COMPONENTS_ROOT, PROJECT_ROOT, COMPONENTS_DIR, HTML_MINIFIER_OPTIONS
66
} from '../constants';
77
import {sassBuildTask, tsBuildTask, execNodeTask, copyTask, sequenceTask} from '../task_helpers';
8-
import {writeFileSync} from 'fs';
98

109
// No typings for these.
1110
const inlineResources = require('../../../scripts/release/inline-resources');
12-
const rollup = require('rollup').rollup;
11+
const gulpRollup = require('gulp-better-rollup');
1312
const gulpMinifyCss = require('gulp-clean-css');
1413
const gulpMinifyHtml = require('gulp-htmlmin');
1514
const gulpIf = require('gulp-if');
@@ -85,30 +84,23 @@ task(':build:components:rollup', () => {
8584
'rxjs/Observable': 'Rx'
8685
};
8786

88-
// Rollup the @angular/material UMD bundle from all ES5 + imports JavaScript files built.
89-
return rollup({
90-
entry: path.join(DIST_COMPONENTS_ROOT, 'index.js'),
87+
const rollupOptions = {
9188
context: 'this',
9289
external: Object.keys(globals)
93-
}).then((bundle: { generate: any }) => {
94-
const result = bundle.generate({
95-
moduleName: 'ng.material',
96-
format: 'umd',
97-
globals,
98-
sourceMap: true,
99-
dest: path.join(DIST_COMPONENTS_ROOT, 'material.umd.js')
100-
});
101-
102-
// Add source map URL to the code.
103-
result.code += '\n\n//# sourceMappingURL=./material.umd.js.map\n';
104-
// Format mapping to show properly in the browser. Rollup by default will put the path
105-
// as relative to the file, and since that path is in src/lib and the file is in
106-
// dist/@angular/material, we need to kill a few `../`.
107-
result.map.sources = result.map.sources.map((s: string) => s.replace(/^(\.\.\/)+/, ''));
108-
109-
writeFileSync(path.join(DIST_COMPONENTS_ROOT, 'material.umd.js'), result.code, 'utf8');
110-
writeFileSync(path.join(DIST_COMPONENTS_ROOT, 'material.umd.js.map'), result.map, 'utf8');
111-
});
90+
};
91+
92+
const rollupGenerateOptions = {
93+
// Keep the moduleId empty because we don't want to force developers to a specific moduleId.
94+
moduleId: '',
95+
moduleName: 'ng.material',
96+
format: 'umd',
97+
globals,
98+
dest: 'material.umd.js'
99+
};
100+
101+
return src(path.join(DIST_COMPONENTS_ROOT, 'index.js'))
102+
.pipe(gulpRollup(rollupOptions, rollupGenerateOptions))
103+
.pipe(dest(path.join(DIST_COMPONENTS_ROOT, 'bundles')));
112104
});
113105

114106
/** Builds components with resources (html, css) inlined into the built JS (ESM output). */

0 commit comments

Comments
 (0)