1 |
|
2 |
|
3 |
|
4 |
|
5 |
|
6 | "use strict";
|
7 |
|
8 | const DllEntryPlugin = require("./DllEntryPlugin");
|
9 | const FlagAllModulesAsUsedPlugin = require("./FlagAllModulesAsUsedPlugin");
|
10 | const LibManifestPlugin = require("./LibManifestPlugin");
|
11 |
|
12 | const { validate } = require("schema-utils");
|
13 | const schema = require("../schemas/plugins/DllPlugin.json");
|
14 |
|
15 |
|
16 |
|
17 |
|
18 | class DllPlugin {
|
19 | |
20 |
|
21 |
|
22 | constructor(options) {
|
23 | validate(schema, options, {
|
24 | name: "Dll Plugin",
|
25 | baseDataPath: "options"
|
26 | });
|
27 | this.options = {
|
28 | ...options,
|
29 | entryOnly: options.entryOnly !== false
|
30 | };
|
31 | }
|
32 |
|
33 | |
34 |
|
35 |
|
36 |
|
37 |
|
38 | apply(compiler) {
|
39 | compiler.hooks.entryOption.tap("DllPlugin", (context, entry) => {
|
40 | if (typeof entry !== "function") {
|
41 | for (const name of Object.keys(entry)) {
|
42 | const options = {
|
43 | name,
|
44 | filename: entry.filename
|
45 | };
|
46 | new DllEntryPlugin(context, entry[name].import, options).apply(
|
47 | compiler
|
48 | );
|
49 | }
|
50 | } else {
|
51 | throw new Error(
|
52 | "DllPlugin doesn't support dynamic entry (function) yet"
|
53 | );
|
54 | }
|
55 | return true;
|
56 | });
|
57 | new LibManifestPlugin(this.options).apply(compiler);
|
58 | if (!this.options.entryOnly) {
|
59 | new FlagAllModulesAsUsedPlugin("DllPlugin").apply(compiler);
|
60 | }
|
61 | }
|
62 | }
|
63 |
|
64 | module.exports = DllPlugin;
|