[6a3a178] | 1 | /*
|
---|
| 2 | MIT License http://www.opensource.org/licenses/mit-license.php
|
---|
| 3 | Author Tobias Koppers @sokra
|
---|
| 4 | */
|
---|
| 5 |
|
---|
| 6 | "use strict";
|
---|
| 7 |
|
---|
| 8 | const DllEntryPlugin = require("./DllEntryPlugin");
|
---|
| 9 | const FlagAllModulesAsUsedPlugin = require("./FlagAllModulesAsUsedPlugin");
|
---|
| 10 | const LibManifestPlugin = require("./LibManifestPlugin");
|
---|
| 11 | const createSchemaValidation = require("./util/create-schema-validation");
|
---|
| 12 |
|
---|
| 13 | /** @typedef {import("../declarations/plugins/DllPlugin").DllPluginOptions} DllPluginOptions */
|
---|
| 14 | /** @typedef {import("./Compiler")} Compiler */
|
---|
| 15 |
|
---|
| 16 | const validate = createSchemaValidation(
|
---|
| 17 | require("../schemas/plugins/DllPlugin.check.js"),
|
---|
| 18 | () => require("../schemas/plugins/DllPlugin.json"),
|
---|
| 19 | {
|
---|
| 20 | name: "Dll Plugin",
|
---|
| 21 | baseDataPath: "options"
|
---|
| 22 | }
|
---|
| 23 | );
|
---|
| 24 |
|
---|
| 25 | class DllPlugin {
|
---|
| 26 | /**
|
---|
| 27 | * @param {DllPluginOptions} options options object
|
---|
| 28 | */
|
---|
| 29 | constructor(options) {
|
---|
| 30 | validate(options);
|
---|
| 31 | this.options = {
|
---|
| 32 | ...options,
|
---|
| 33 | entryOnly: options.entryOnly !== false
|
---|
| 34 | };
|
---|
| 35 | }
|
---|
| 36 |
|
---|
| 37 | /**
|
---|
| 38 | * Apply the plugin
|
---|
| 39 | * @param {Compiler} compiler the compiler instance
|
---|
| 40 | * @returns {void}
|
---|
| 41 | */
|
---|
| 42 | apply(compiler) {
|
---|
| 43 | compiler.hooks.entryOption.tap("DllPlugin", (context, entry) => {
|
---|
| 44 | if (typeof entry !== "function") {
|
---|
| 45 | for (const name of Object.keys(entry)) {
|
---|
| 46 | const options = {
|
---|
| 47 | name,
|
---|
| 48 | filename: entry.filename
|
---|
| 49 | };
|
---|
| 50 | new DllEntryPlugin(context, entry[name].import, options).apply(
|
---|
| 51 | compiler
|
---|
| 52 | );
|
---|
| 53 | }
|
---|
| 54 | } else {
|
---|
| 55 | throw new Error(
|
---|
| 56 | "DllPlugin doesn't support dynamic entry (function) yet"
|
---|
| 57 | );
|
---|
| 58 | }
|
---|
| 59 | return true;
|
---|
| 60 | });
|
---|
| 61 | new LibManifestPlugin(this.options).apply(compiler);
|
---|
| 62 | if (!this.options.entryOnly) {
|
---|
| 63 | new FlagAllModulesAsUsedPlugin("DllPlugin").apply(compiler);
|
---|
| 64 | }
|
---|
| 65 | }
|
---|
| 66 | }
|
---|
| 67 |
|
---|
| 68 | module.exports = DllPlugin;
|
---|