1 |
|
2 |
|
3 |
|
4 |
|
5 |
|
6 | "use strict";
|
7 |
|
8 |
|
9 |
|
10 |
|
11 |
|
12 |
|
13 | class EntryOptionPlugin {
|
14 | |
15 |
|
16 |
|
17 |
|
18 | apply(compiler) {
|
19 | compiler.hooks.entryOption.tap("EntryOptionPlugin", (context, entry) => {
|
20 | EntryOptionPlugin.applyEntryOption(compiler, context, entry);
|
21 | return true;
|
22 | });
|
23 | }
|
24 |
|
25 | |
26 |
|
27 |
|
28 |
|
29 |
|
30 |
|
31 | static applyEntryOption(compiler, context, entry) {
|
32 | if (typeof entry === "function") {
|
33 | const DynamicEntryPlugin = require("./DynamicEntryPlugin");
|
34 | new DynamicEntryPlugin(context, entry).apply(compiler);
|
35 | } else {
|
36 | const EntryPlugin = require("./EntryPlugin");
|
37 | for (const name of Object.keys(entry)) {
|
38 | const desc = entry[name];
|
39 | const options = EntryOptionPlugin.entryDescriptionToOptions(
|
40 | compiler,
|
41 | name,
|
42 | desc
|
43 | );
|
44 | for (const entry of desc.import) {
|
45 | new EntryPlugin(context, entry, options).apply(compiler);
|
46 | }
|
47 | }
|
48 | }
|
49 | }
|
50 |
|
51 | |
52 |
|
53 |
|
54 |
|
55 |
|
56 |
|
57 | static entryDescriptionToOptions(compiler, name, desc) {
|
58 |
|
59 | const options = {
|
60 | name,
|
61 | filename: desc.filename,
|
62 | runtime: desc.runtime,
|
63 | layer: desc.layer,
|
64 | dependOn: desc.dependOn,
|
65 | chunkLoading: desc.chunkLoading,
|
66 | wasmLoading: desc.wasmLoading,
|
67 | library: desc.library
|
68 | };
|
69 | if (desc.layer !== undefined && !compiler.options.experiments.layers) {
|
70 | throw new Error(
|
71 | "'entryOptions.layer' is only allowed when 'experiments.layers' is enabled"
|
72 | );
|
73 | }
|
74 | if (desc.chunkLoading) {
|
75 | const EnableChunkLoadingPlugin = require("./javascript/EnableChunkLoadingPlugin");
|
76 | EnableChunkLoadingPlugin.checkEnabled(compiler, desc.chunkLoading);
|
77 | }
|
78 | if (desc.wasmLoading) {
|
79 | const EnableWasmLoadingPlugin = require("./wasm/EnableWasmLoadingPlugin");
|
80 | EnableWasmLoadingPlugin.checkEnabled(compiler, desc.wasmLoading);
|
81 | }
|
82 | if (desc.library) {
|
83 | const EnableLibraryPlugin = require("./library/EnableLibraryPlugin");
|
84 | EnableLibraryPlugin.checkEnabled(compiler, desc.library.type);
|
85 | }
|
86 | return options;
|
87 | }
|
88 | }
|
89 |
|
90 | module.exports = EntryOptionPlugin;
|