2015-05-17 00:27:59 +08:00
|
|
|
/*
|
|
|
|
MIT License http://www.opensource.org/licenses/mit-license.php
|
|
|
|
Author Tobias Koppers @sokra
|
2018-07-30 23:08:51 +08:00
|
|
|
*/
|
|
|
|
|
2017-01-05 13:59:22 +08:00
|
|
|
"use strict";
|
2015-05-17 00:27:59 +08:00
|
|
|
|
2017-01-05 13:59:22 +08:00
|
|
|
const DllEntryPlugin = require("./DllEntryPlugin");
|
2020-01-03 00:37:47 +08:00
|
|
|
const FlagAllModulesAsUsedPlugin = require("./FlagAllModulesAsUsedPlugin");
|
2018-07-30 23:08:51 +08:00
|
|
|
const LibManifestPlugin = require("./LibManifestPlugin");
|
2017-01-05 13:59:22 +08:00
|
|
|
|
2020-10-06 02:41:45 +08:00
|
|
|
const { validate } = require("schema-utils");
|
2017-11-11 20:05:55 +08:00
|
|
|
const schema = require("../schemas/plugins/DllPlugin.json");
|
2017-10-28 05:23:38 +08:00
|
|
|
|
2018-09-20 16:13:55 +08:00
|
|
|
/** @typedef {import("../declarations/plugins/DllPlugin").DllPluginOptions} DllPluginOptions */
|
2020-02-17 17:27:46 +08:00
|
|
|
/** @typedef {import("./Compiler")} Compiler */
|
2018-09-20 16:13:55 +08:00
|
|
|
|
2017-01-05 13:59:22 +08:00
|
|
|
class DllPlugin {
|
2018-09-20 16:13:55 +08:00
|
|
|
/**
|
|
|
|
* @param {DllPluginOptions} options options object
|
|
|
|
*/
|
2017-01-05 13:59:22 +08:00
|
|
|
constructor(options) {
|
2020-10-06 02:41:45 +08:00
|
|
|
validate(schema, options, {
|
2019-08-07 21:55:03 +08:00
|
|
|
name: "Dll Plugin",
|
|
|
|
baseDataPath: "options"
|
|
|
|
});
|
2020-01-03 00:46:21 +08:00
|
|
|
this.options = {
|
|
|
|
...options,
|
|
|
|
entryOnly: options.entryOnly !== false
|
|
|
|
};
|
2017-01-05 13:59:22 +08:00
|
|
|
}
|
|
|
|
|
2020-02-17 17:27:46 +08:00
|
|
|
/**
|
2020-04-23 16:48:36 +08:00
|
|
|
* Apply the plugin
|
|
|
|
* @param {Compiler} compiler the compiler instance
|
2020-02-17 17:27:46 +08:00
|
|
|
* @returns {void}
|
|
|
|
*/
|
2017-01-05 13:59:22 +08:00
|
|
|
apply(compiler) {
|
2017-12-06 22:01:25 +08:00
|
|
|
compiler.hooks.entryOption.tap("DllPlugin", (context, entry) => {
|
2020-02-17 17:27:46 +08:00
|
|
|
if (typeof entry !== "function") {
|
|
|
|
for (const name of Object.keys(entry)) {
|
|
|
|
const options = {
|
|
|
|
name,
|
|
|
|
filename: entry.filename
|
|
|
|
};
|
|
|
|
new DllEntryPlugin(context, entry[name].import, options).apply(
|
|
|
|
compiler
|
|
|
|
);
|
2018-05-29 20:50:40 +08:00
|
|
|
}
|
2017-01-05 13:59:22 +08:00
|
|
|
} else {
|
2020-02-17 17:27:46 +08:00
|
|
|
throw new Error(
|
|
|
|
"DllPlugin doesn't support dynamic entry (function) yet"
|
|
|
|
);
|
2017-01-05 13:59:22 +08:00
|
|
|
}
|
|
|
|
return true;
|
|
|
|
});
|
2017-12-20 16:53:33 +08:00
|
|
|
new LibManifestPlugin(this.options).apply(compiler);
|
2018-05-19 03:13:10 +08:00
|
|
|
if (!this.options.entryOnly) {
|
2020-01-03 00:37:47 +08:00
|
|
|
new FlagAllModulesAsUsedPlugin("DllPlugin").apply(compiler);
|
2018-05-19 03:13:10 +08:00
|
|
|
}
|
2017-01-05 13:59:22 +08:00
|
|
|
}
|
2015-05-17 00:27:59 +08:00
|
|
|
}
|
2017-01-05 13:59:22 +08:00
|
|
|
|
2015-05-17 00:27:59 +08:00
|
|
|
module.exports = DllPlugin;
|