1 |
|
2 |
|
3 |
|
4 |
|
5 | "use strict";
|
6 | const SingleEntryDependency = require("./dependencies/SingleEntryDependency");
|
7 |
|
8 |
|
9 |
|
10 | class SingleEntryPlugin {
|
11 | |
12 |
|
13 |
|
14 |
|
15 |
|
16 |
|
17 |
|
18 |
|
19 | constructor(context, entry, name) {
|
20 | this.context = context;
|
21 | this.entry = entry;
|
22 | this.name = name;
|
23 | }
|
24 |
|
25 | |
26 |
|
27 |
|
28 |
|
29 | apply(compiler) {
|
30 | compiler.hooks.compilation.tap(
|
31 | "SingleEntryPlugin",
|
32 | (compilation, { normalModuleFactory }) => {
|
33 | compilation.dependencyFactories.set(
|
34 | SingleEntryDependency,
|
35 | normalModuleFactory
|
36 | );
|
37 | }
|
38 | );
|
39 |
|
40 | compiler.hooks.make.tapAsync(
|
41 | "SingleEntryPlugin",
|
42 | (compilation, callback) => {
|
43 | const { entry, name, context } = this;
|
44 |
|
45 | const dep = SingleEntryPlugin.createDependency(entry, name);
|
46 | compilation.addEntry(context, dep, name, callback);
|
47 | }
|
48 | );
|
49 | }
|
50 |
|
51 | |
52 |
|
53 |
|
54 |
|
55 |
|
56 | static createDependency(entry, name) {
|
57 | const dep = new SingleEntryDependency(entry);
|
58 | dep.loc = { name };
|
59 | return dep;
|
60 | }
|
61 | }
|
62 |
|
63 | module.exports = SingleEntryPlugin;
|