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
|
static defaultNameResolver(chunk) {
|
9
|
return chunk.name || null;
|
10
|
}
|
11
|
|
12
|
constructor(nameResolver) {
|
13
|
this.nameResolver = nameResolver || NamedChunksPlugin.defaultNameResolver;
|
14
|
}
|
15
|
|
16
|
apply(compiler) {
|
17
|
compiler.hooks.compilation.tap("NamedChunksPlugin", compilation => {
|
18
|
compilation.hooks.beforeChunkIds.tap("NamedChunksPlugin", chunks => {
|
19
|
for (const chunk of chunks) {
|
20
|
if (chunk.id === null) {
|
21
|
chunk.id = this.nameResolver(chunk);
|
22
|
}
|
23
|
}
|
24
|
});
|
25
|
});
|
26
|
}
|
27
|
}
|
28
|
|
29
|
module.exports = NamedChunksPlugin;
|