2015-05-17 00:27:59 +08:00
|
|
|
/*
|
|
|
|
MIT License http://www.opensource.org/licenses/mit-license.php
|
|
|
|
Author Tobias Koppers @sokra
|
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");
|
|
|
|
const LibManifestPlugin = require("./LibManifestPlugin");
|
|
|
|
const FlagInitialModulesAsUsedPlugin = require("./FlagInitialModulesAsUsedPlugin");
|
|
|
|
|
2017-10-29 17:19:28 +08:00
|
|
|
const validateOptions = 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
|
|
|
|
2017-01-05 13:59:22 +08:00
|
|
|
class DllPlugin {
|
|
|
|
constructor(options) {
|
2017-11-11 20:05:55 +08:00
|
|
|
validateOptions(schema, options, "Dll Plugin");
|
2017-01-05 13:59:22 +08:00
|
|
|
this.options = options;
|
|
|
|
}
|
|
|
|
|
|
|
|
apply(compiler) {
|
2017-12-06 22:01:25 +08:00
|
|
|
compiler.hooks.entryOption.tap("DllPlugin", (context, entry) => {
|
2017-11-08 18:32:05 +08:00
|
|
|
const itemToPlugin = (item, name) => {
|
2018-05-29 20:50:40 +08:00
|
|
|
if (Array.isArray(item)) {
|
|
|
|
return new DllEntryPlugin(context, item, name);
|
|
|
|
}
|
|
|
|
throw new Error("DllPlugin: supply an Array as entry");
|
2017-11-08 18:32:05 +08:00
|
|
|
};
|
2018-02-25 09:00:20 +08:00
|
|
|
if (typeof entry === "object" && !Array.isArray(entry)) {
|
2017-01-05 13:59:22 +08:00
|
|
|
Object.keys(entry).forEach(name => {
|
2017-12-20 16:53:33 +08:00
|
|
|
itemToPlugin(entry[name], name).apply(compiler);
|
2017-01-05 13:59:22 +08:00
|
|
|
});
|
|
|
|
} else {
|
2017-12-20 16:53:33 +08:00
|
|
|
itemToPlugin(entry, "main").apply(compiler);
|
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) {
|
|
|
|
new FlagInitialModulesAsUsedPlugin("DllPlugin").apply(compiler);
|
|
|
|
}
|
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;
|