webpack/lib/DllEntryPlugin.js

73 lines
1.7 KiB
JavaScript
Raw Normal View History

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
2016-12-29 16:33:01 +08:00
"use strict";
2015-05-17 00:27:59 +08:00
2018-07-30 23:08:51 +08:00
const DllModuleFactory = require("./DllModuleFactory");
2016-12-29 16:33:01 +08:00
const DllEntryDependency = require("./dependencies/DllEntryDependency");
const EntryDependency = require("./dependencies/EntryDependency");
2016-12-29 16:33:01 +08:00
2023-06-17 02:24:34 +08:00
/** @typedef {import("./Compiler")} Compiler */
2024-08-06 11:08:48 +08:00
/** @typedef {string[]} Entries */
/** @typedef {{ name: string, filename: TODO }} Options */
2023-06-17 02:24:34 +08:00
2016-12-29 16:33:01 +08:00
class DllEntryPlugin {
2023-05-22 05:47:28 +08:00
/**
* @param {string} context context
2024-08-06 11:08:48 +08:00
* @param {Entries} entries entry names
* @param {Options} options options
2023-05-22 05:47:28 +08:00
*/
constructor(context, entries, options) {
2016-12-29 16:33:01 +08:00
this.context = context;
this.entries = entries;
this.options = options;
2016-12-29 16:33:01 +08:00
}
2023-06-17 02:24:34 +08:00
/**
* Apply the plugin
* @param {Compiler} compiler the compiler instance
* @returns {void}
*/
2016-12-29 16:33:01 +08:00
apply(compiler) {
2018-02-25 09:00:20 +08:00
compiler.hooks.compilation.tap(
"DllEntryPlugin",
(compilation, { normalModuleFactory }) => {
const dllModuleFactory = new DllModuleFactory();
compilation.dependencyFactories.set(
DllEntryDependency,
dllModuleFactory
);
compilation.dependencyFactories.set(
EntryDependency,
2018-02-25 09:00:20 +08:00
normalModuleFactory
);
}
);
2017-12-06 22:01:25 +08:00
compiler.hooks.make.tapAsync("DllEntryPlugin", (compilation, callback) => {
2018-02-25 09:00:20 +08:00
compilation.addEntry(
this.context,
new DllEntryDependency(
this.entries.map((e, idx) => {
const dep = new EntryDependency(e);
dep.loc = {
name: this.options.name,
index: idx
};
2018-02-25 09:00:20 +08:00
return dep;
}),
this.options.name
2018-02-25 09:00:20 +08:00
),
this.options,
2023-06-17 02:49:43 +08:00
error => {
if (error) return callback(error);
callback();
}
2018-02-25 09:00:20 +08:00
);
2016-12-29 16:33:01 +08:00
});
}
}
module.exports = DllEntryPlugin;