1 |
|
2 |
|
3 |
|
4 |
|
5 |
|
6 | "use strict";
|
7 |
|
8 |
|
9 |
|
10 | class RuntimeChunkPlugin {
|
11 | constructor(options) {
|
12 | this.options = {
|
13 | name: entrypoint => `runtime~${entrypoint.name}`,
|
14 | ...options
|
15 | };
|
16 | }
|
17 |
|
18 | |
19 |
|
20 |
|
21 |
|
22 |
|
23 | apply(compiler) {
|
24 | compiler.hooks.thisCompilation.tap("RuntimeChunkPlugin", compilation => {
|
25 | compilation.hooks.addEntry.tap(
|
26 | "RuntimeChunkPlugin",
|
27 | (_, { name: entryName }) => {
|
28 | if (entryName === undefined) return;
|
29 | const data = compilation.entries.get(entryName);
|
30 | if (data.options.runtime === undefined && !data.options.dependOn) {
|
31 |
|
32 | let name = this.options.name;
|
33 | if (typeof name === "function") {
|
34 | name = name({ name: entryName });
|
35 | }
|
36 | data.options.runtime = name;
|
37 | }
|
38 | }
|
39 | );
|
40 | });
|
41 | }
|
42 | }
|
43 |
|
44 | module.exports = RuntimeChunkPlugin;
|