Skip to content

Commit 376badb

Browse files
committed
introduce named chunks plugin
1 parent 2e87cab commit 376badb

File tree

1 file changed

+30
-0
lines changed

1 file changed

+30
-0
lines changed

lib/NamedChunksPlugin.js

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
/*
2+
MIT License http://www.opensource.org/licenses/mit-license.php
3+
Author Tobias Koppers @sokra
4+
*/
5+
"use strict";
6+
7+
class NamedChunksPlugin {
8+
9+
static defaultNameResolver(chunk) {
10+
return chunk.name || null;
11+
}
12+
13+
constructor(nameResolver) {
14+
this.nameResolver = nameResolver || NamedChunksPlugin.defaultNameResolver;
15+
}
16+
17+
apply(compiler) {
18+
compiler.plugin("compilation", (compilation) => {
19+
compilation.plugin("before-chunk-ids", (chunks) => {
20+
chunks.forEach((chunk) => {
21+
if(chunk.id === null) {
22+
chunk.id = this.nameResolver(chunk);
23+
}
24+
});
25+
});
26+
});
27+
}
28+
}
29+
30+
module.exports = NamedChunksPlugin;

0 commit comments

Comments
 (0)