1 |
|
2 |
|
3 |
|
4 |
|
5 | "use strict";
|
6 |
|
7 | const MultiEntryDependency = require("./dependencies/MultiEntryDependency");
|
8 | const SingleEntryDependency = require("./dependencies/SingleEntryDependency");
|
9 | const MultiModuleFactory = require("./MultiModuleFactory");
|
10 |
|
11 |
|
12 |
|
13 | class MultiEntryPlugin {
|
14 | |
15 |
|
16 |
|
17 |
|
18 |
|
19 |
|
20 | constructor(context, entries, name) {
|
21 | this.context = context;
|
22 | this.entries = entries;
|
23 | this.name = name;
|
24 | }
|
25 |
|
26 | |
27 |
|
28 |
|
29 |
|
30 | apply(compiler) {
|
31 | compiler.hooks.compilation.tap(
|
32 | "MultiEntryPlugin",
|
33 | (compilation, { normalModuleFactory }) => {
|
34 | const multiModuleFactory = new MultiModuleFactory();
|
35 |
|
36 | compilation.dependencyFactories.set(
|
37 | MultiEntryDependency,
|
38 | multiModuleFactory
|
39 | );
|
40 | compilation.dependencyFactories.set(
|
41 | SingleEntryDependency,
|
42 | normalModuleFactory
|
43 | );
|
44 | }
|
45 | );
|
46 |
|
47 | compiler.hooks.make.tapAsync(
|
48 | "MultiEntryPlugin",
|
49 | (compilation, callback) => {
|
50 | const { context, entries, name } = this;
|
51 |
|
52 | const dep = MultiEntryPlugin.createDependency(entries, name);
|
53 | compilation.addEntry(context, dep, name, callback);
|
54 | }
|
55 | );
|
56 | }
|
57 |
|
58 | |
59 |
|
60 |
|
61 |
|
62 |
|
63 | static createDependency(entries, name) {
|
64 | return new MultiEntryDependency(
|
65 | entries.map((e, idx) => {
|
66 | const dep = new SingleEntryDependency(e);
|
67 |
|
68 |
|
69 | dep.loc = {
|
70 | name,
|
71 | index: idx
|
72 | };
|
73 | return dep;
|
74 | }),
|
75 | name
|
76 | );
|
77 | }
|
78 | }
|
79 |
|
80 | module.exports = MultiEntryPlugin;
|