| | |
| | | const DllEntryPlugin = require("./DllEntryPlugin"); |
| | | const FlagAllModulesAsUsedPlugin = require("./FlagAllModulesAsUsedPlugin"); |
| | | const LibManifestPlugin = require("./LibManifestPlugin"); |
| | | const createSchemaValidation = require("./util/create-schema-validation"); |
| | | |
| | | /** @typedef {import("../declarations/plugins/DllPlugin").DllPluginOptions} DllPluginOptions */ |
| | | /** @typedef {import("./Compiler")} Compiler */ |
| | | /** @typedef {import("./DllEntryPlugin").Entries} Entries */ |
| | | /** @typedef {import("./DllEntryPlugin").Options} Options */ |
| | | |
| | | const validate = createSchemaValidation( |
| | | require("../schemas/plugins/DllPlugin.check"), |
| | | () => require("../schemas/plugins/DllPlugin.json"), |
| | | { |
| | | name: "Dll Plugin", |
| | | baseDataPath: "options" |
| | | } |
| | | ); |
| | | |
| | | const PLUGIN_NAME = "DllPlugin"; |
| | | |
| | | class DllPlugin { |
| | | /** |
| | | * Creates an instance of DllPlugin. |
| | | * @param {DllPluginOptions} options options object |
| | | */ |
| | | constructor(options) { |
| | | validate(options); |
| | | this.options = { |
| | | ...options, |
| | | entryOnly: options.entryOnly !== false |
| | | }; |
| | | /** @type {DllPluginOptions} */ |
| | | this.options = options; |
| | | } |
| | | |
| | | /** |
| | | * Apply the plugin |
| | | * Applies the plugin by registering its hooks on the compiler. |
| | | * @param {Compiler} compiler the compiler instance |
| | | * @returns {void} |
| | | */ |
| | | apply(compiler) { |
| | | compiler.hooks.validate.tap(PLUGIN_NAME, () => { |
| | | compiler.validate( |
| | | () => require("../schemas/plugins/DllPlugin.json"), |
| | | this.options, |
| | | { |
| | | name: "Dll Plugin", |
| | | baseDataPath: "options" |
| | | }, |
| | | (options) => require("../schemas/plugins/DllPlugin.check")(options) |
| | | ); |
| | | }); |
| | | |
| | | const entryOnly = this.options.entryOnly !== false; |
| | | compiler.hooks.entryOption.tap(PLUGIN_NAME, (context, entry) => { |
| | | if (typeof entry !== "function") { |
| | | for (const name of Object.keys(entry)) { |
| | |
| | | } |
| | | return true; |
| | | }); |
| | | new LibManifestPlugin(this.options).apply(compiler); |
| | | if (!this.options.entryOnly) { |
| | | new LibManifestPlugin({ ...this.options, entryOnly }).apply(compiler); |
| | | if (!entryOnly) { |
| | | new FlagAllModulesAsUsedPlugin(PLUGIN_NAME).apply(compiler); |
| | | } |
| | | } |