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