1 |
|
2 |
|
3 |
|
4 |
|
5 | "use strict";
|
6 |
|
7 | const SingleEntryPlugin = require("./SingleEntryPlugin");
|
8 | const MultiEntryPlugin = require("./MultiEntryPlugin");
|
9 | const DynamicEntryPlugin = require("./DynamicEntryPlugin");
|
10 |
|
11 |
|
12 |
|
13 |
|
14 |
|
15 |
|
16 |
|
17 |
|
18 |
|
19 |
|
20 | const itemToPlugin = (context, item, name) => {
|
21 | if (Array.isArray(item)) {
|
22 | return new MultiEntryPlugin(context, item, name);
|
23 | }
|
24 | return new SingleEntryPlugin(context, item, name);
|
25 | };
|
26 |
|
27 | module.exports = class EntryOptionPlugin {
|
28 | |
29 |
|
30 |
|
31 |
|
32 | apply(compiler) {
|
33 | compiler.hooks.entryOption.tap("EntryOptionPlugin", (context, entry) => {
|
34 | if (typeof entry === "string" || Array.isArray(entry)) {
|
35 | itemToPlugin(context, entry, "main").apply(compiler);
|
36 | } else if (typeof entry === "object") {
|
37 | for (const name of Object.keys(entry)) {
|
38 | itemToPlugin(context, entry[name], name).apply(compiler);
|
39 | }
|
40 | } else if (typeof entry === "function") {
|
41 | new DynamicEntryPlugin(context, entry).apply(compiler);
|
42 | }
|
43 | return true;
|
44 | });
|
45 | }
|
46 | };
|