Skip to content

Commit b53002c

Browse files
devversiontinayuangao
authored andcommitted
build: add package name to AMD modules (#10177)
* Fixes that the UMD bundles, which use the `define` function in AMD mode, don't have a module name. This feature has been added in later versions of Rollup, so we had to upgrade. By comparing with the previous UMD bundles, the bundles still seem to work properly (also in our demo-app). Fixes #10142
1 parent e21015d commit b53002c

File tree

2 files changed

+17
-10
lines changed

2 files changed

+17
-10
lines changed

package.json

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -111,9 +111,9 @@
111111
"protractor": "^5.2.0",
112112
"request": "^2.83.0",
113113
"resolve-bin": "^0.4.0",
114-
"rollup": "^0.41.6",
115-
"rollup-plugin-alias": "^1.3.1",
116-
"rollup-plugin-node-resolve": "^3.0.0",
114+
"rollup": "^0.56.3",
115+
"rollup-plugin-alias": "^1.4.0",
116+
"rollup-plugin-node-resolve": "^3.0.3",
117117
"run-sequence": "^1.2.2",
118118
"scss-bundle": "^2.0.1-beta.7",
119119
"selenium-webdriver": "^3.6.0",

tools/package-tools/build-bundles.ts

Lines changed: 14 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@ export class PackageBundler {
3535
return this.bundleEntryPoint({
3636
entryFile: this.buildPackage.entryFilePath,
3737
esm5EntryFile: join(this.buildPackage.esm5OutputDir, 'index.js'),
38+
importName: `@angular/${this.buildPackage.name}`,
3839
moduleName: `ng.${this.buildPackage.name}`,
3940
esm2015Dest: join(bundlesDir, `${packageName}.js`),
4041
esm5Dest: join(bundlesDir, `${packageName}.es5.js`),
@@ -48,11 +49,13 @@ export class PackageBundler {
4849
const packageName = this.buildPackage.name;
4950
const entryFile = join(this.buildPackage.outputDir, entryPoint, 'index.js');
5051
const esm5EntryFile = join(this.buildPackage.esm5OutputDir, entryPoint, 'index.js');
52+
const dashedEntryName = dashCaseToCamelCase(entryPoint);
5153

5254
return this.bundleEntryPoint({
5355
entryFile,
5456
esm5EntryFile,
55-
moduleName: `ng.${packageName}.${dashCaseToCamelCase(entryPoint)}`,
57+
importName: `@angular/${this.buildPackage.name}/${dashedEntryName}`,
58+
moduleName: `ng.${packageName}.${dashedEntryName}`,
5659
esm2015Dest: join(bundlesDir, `${packageName}`, `${entryPoint}.js`),
5760
esm5Dest: join(bundlesDir, `${packageName}`, `${entryPoint}.es5.js`),
5861
umdDest: join(bundlesDir, `${packageName}-${entryPoint}.umd.js`),
@@ -68,6 +71,7 @@ export class PackageBundler {
6871
private async bundleEntryPoint(config: BundlesConfig) {
6972
// Build FESM-2015 bundle file.
7073
await this.createRollupBundle({
74+
importName: config.importName,
7175
moduleName: config.moduleName,
7276
entry: config.entryFile,
7377
dest: config.esm2015Dest,
@@ -76,6 +80,7 @@ export class PackageBundler {
7680

7781
// Build FESM-5 bundle file.
7882
await this.createRollupBundle({
83+
importName: config.importName,
7984
moduleName: config.moduleName,
8085
entry: config.esm5EntryFile,
8186
dest: config.esm5Dest,
@@ -84,6 +89,7 @@ export class PackageBundler {
8489

8590
// Create UMD bundle of ES5 output.
8691
await this.createRollupBundle({
92+
importName: config.importName,
8793
moduleName: config.moduleName,
8894
entry: config.esm5Dest,
8995
dest: config.umdDest,
@@ -105,7 +111,7 @@ export class PackageBundler {
105111
const bundleOptions = {
106112
context: 'this',
107113
external: Object.keys(rollupGlobals),
108-
entry: config.entry,
114+
input: config.entry,
109115
onwarn: (message: string) => {
110116
// TODO(jelbourn): figure out *why* rollup warns about certain symbols not being found
111117
// when those symbols don't appear to be in the input file in the first place.
@@ -121,14 +127,13 @@ export class PackageBundler {
121127
};
122128

123129
const writeOptions = {
124-
// Keep the moduleId empty because we don't want to force developers to a specific moduleId.
125-
moduleId: '',
126-
moduleName: config.moduleName || 'ng.material',
130+
name: config.moduleName || 'ng.material',
131+
amd: {id: config.importName},
127132
banner: buildConfig.licenseBanner,
128133
format: config.format,
129-
dest: config.dest,
134+
file: config.dest,
130135
globals: rollupGlobals,
131-
sourceMap: true
136+
sourcemap: true
132137
};
133138

134139
// For UMD bundles, we need to adjust the `external` bundle option in order to include
@@ -183,6 +188,7 @@ export class PackageBundler {
183188
interface BundlesConfig {
184189
entryFile: string;
185190
esm5EntryFile: string;
191+
importName: string;
186192
moduleName: string;
187193
esm2015Dest: string;
188194
esm5Dest: string;
@@ -196,4 +202,5 @@ interface RollupBundleConfig {
196202
dest: string;
197203
format: string;
198204
moduleName: string;
205+
importName: string;
199206
}

0 commit comments

Comments
 (0)