1 |
|
2 |
|
3 |
|
4 |
|
5 | "use strict";
|
6 |
|
7 | const DllEntryPlugin = require("./DllEntryPlugin");
|
8 | const LibManifestPlugin = require("./LibManifestPlugin");
|
9 | const FlagInitialModulesAsUsedPlugin = require("./FlagInitialModulesAsUsedPlugin");
|
10 |
|
11 | const validateOptions = require("schema-utils");
|
12 | const schema = require("../schemas/plugins/DllPlugin.json");
|
13 |
|
14 |
|
15 |
|
16 | class DllPlugin {
|
17 | |
18 |
|
19 |
|
20 | constructor(options) {
|
21 | validateOptions(schema, options, "Dll Plugin");
|
22 | this.options = options;
|
23 | }
|
24 |
|
25 | apply(compiler) {
|
26 | compiler.hooks.entryOption.tap("DllPlugin", (context, entry) => {
|
27 | const itemToPlugin = (item, name) => {
|
28 | if (Array.isArray(item)) {
|
29 | return new DllEntryPlugin(context, item, name);
|
30 | }
|
31 | throw new Error("DllPlugin: supply an Array as entry");
|
32 | };
|
33 | if (typeof entry === "object" && !Array.isArray(entry)) {
|
34 | Object.keys(entry).forEach(name => {
|
35 | itemToPlugin(entry[name], name).apply(compiler);
|
36 | });
|
37 | } else {
|
38 | itemToPlugin(entry, "main").apply(compiler);
|
39 | }
|
40 | return true;
|
41 | });
|
42 | new LibManifestPlugin(this.options).apply(compiler);
|
43 | if (!this.options.entryOnly) {
|
44 | new FlagInitialModulesAsUsedPlugin("DllPlugin").apply(compiler);
|
45 | }
|
46 | }
|
47 | }
|
48 |
|
49 | module.exports = DllPlugin;
|