Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Prioritize manual chunk name over dynamic entry id #4040

Merged
merged 1 commit into from Apr 13, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
14 changes: 10 additions & 4 deletions src/Chunk.ts
Expand Up @@ -187,6 +187,7 @@ export default class Chunk {
private dependencies = new Set<ExternalModule | Chunk>();
private dynamicDependencies = new Set<ExternalModule | Chunk>();
private dynamicEntryModules: Module[] = [];
private dynamicName: string | null = null;
private exportNamesByVariable = new Map<Variable, string[]>();
private exports = new Set<Variable>();
private exportsByName: Record<string, Variable> = Object.create(null);
Expand Down Expand Up @@ -384,7 +385,7 @@ export default class Chunk {
this.facadeModule = module;
this.facadeChunkByModule.set(module, this);
this.strictFacade = true;
this.assignFacadeName({}, module);
this.dynamicName = getChunkNameFromModule(module);
} else if (
this.facadeModule === module &&
!this.strictFacade &&
Expand Down Expand Up @@ -815,9 +816,7 @@ export default class Chunk {
if (fileName) {
this.fileName = fileName;
} else {
this.name = sanitizeFileName(
name || facadedModule.chunkName || getAliasName(facadedModule.id)
);
this.name = sanitizeFileName(name || getChunkNameFromModule(facadedModule));
}
}

Expand Down Expand Up @@ -1080,6 +1079,9 @@ export default class Chunk {
if (this.manualChunkAlias) {
return this.manualChunkAlias;
}
if (this.dynamicName) {
return this.dynamicName;
}
if (this.fileName) {
return getAliasName(this.fileName);
}
Expand Down Expand Up @@ -1370,3 +1372,7 @@ export default class Chunk {
}
}
}

function getChunkNameFromModule(module: Module): string {
return module.chunkName || getAliasName(module.id);
}
12 changes: 12 additions & 0 deletions test/chunking-form/samples/single-file-manual-chunk/_config.js
@@ -0,0 +1,12 @@
module.exports = {
description: 'chunk aliasing with extensions',
options: {
output: {
manualChunks(id) {
if (id.endsWith('main.js')) return;
if (id.endsWith('a.js')) return 'first';
return 'second';
}
}
}
};
@@ -0,0 +1,5 @@
define(function () { 'use strict';

console.log('a');

});
@@ -0,0 +1,18 @@
define(['exports'], function (exports) { 'use strict';

console.log('b');

var b = /*#__PURE__*/Object.freeze({
__proto__: null
});

console.log('c');

var c = /*#__PURE__*/Object.freeze({
__proto__: null
});

exports.b = b;
exports.c = c;

});
@@ -0,0 +1,7 @@
define(['require'], function (require) { 'use strict';

new Promise(function (resolve, reject) { require(['./generated-first'], resolve, reject) });
new Promise(function (resolve, reject) { require(['./generated-second'], resolve, reject) }).then(function (n) { return n.b; });
new Promise(function (resolve, reject) { require(['./generated-second'], resolve, reject) }).then(function (n) { return n.c; });

});
@@ -0,0 +1,3 @@
'use strict';

console.log('a');
@@ -0,0 +1,16 @@
'use strict';

console.log('b');

var b = /*#__PURE__*/Object.freeze({
__proto__: null
});

console.log('c');

var c = /*#__PURE__*/Object.freeze({
__proto__: null
});

exports.b = b;
exports.c = c;
@@ -0,0 +1,5 @@
'use strict';

Promise.resolve().then(function () { return require('./generated-first.js'); });
Promise.resolve().then(function () { return require('./generated-second.js'); }).then(function (n) { return n.b; });
Promise.resolve().then(function () { return require('./generated-second.js'); }).then(function (n) { return n.c; });
@@ -0,0 +1 @@
console.log('a');
@@ -0,0 +1,13 @@
console.log('b');

var b = /*#__PURE__*/Object.freeze({
__proto__: null
});

console.log('c');

var c = /*#__PURE__*/Object.freeze({
__proto__: null
});

export { b, c };
@@ -0,0 +1,3 @@
import('./generated-first.js');
import('./generated-second.js').then(function (n) { return n.b; });
import('./generated-second.js').then(function (n) { return n.c; });
@@ -0,0 +1,10 @@
System.register([], function () {
'use strict';
return {
execute: function () {

console.log('a');

}
};
});
@@ -0,0 +1,22 @@
System.register([], function (exports) {
'use strict';
return {
execute: function () {

console.log('b');

var b = /*#__PURE__*/Object.freeze({
__proto__: null
});
exports('b', b);

console.log('c');

var c = /*#__PURE__*/Object.freeze({
__proto__: null
});
exports('c', c);

}
};
});
@@ -0,0 +1,12 @@
System.register([], function (exports, module) {
'use strict';
return {
execute: function () {

module.import('./generated-first.js');
module.import('./generated-second.js').then(function (n) { return n.b; });
module.import('./generated-second.js').then(function (n) { return n.c; });

}
};
});
1 change: 1 addition & 0 deletions test/chunking-form/samples/single-file-manual-chunk/a.js
@@ -0,0 +1 @@
console.log('a');
1 change: 1 addition & 0 deletions test/chunking-form/samples/single-file-manual-chunk/b.js
@@ -0,0 +1 @@
console.log('b');
1 change: 1 addition & 0 deletions test/chunking-form/samples/single-file-manual-chunk/c.js
@@ -0,0 +1 @@
console.log('c');
3 changes: 3 additions & 0 deletions test/chunking-form/samples/single-file-manual-chunk/main.js
@@ -0,0 +1,3 @@
import('./a.js');
import('./b.js');
import('./c.js');