webpack/lib/DllEntryPlugin.js

56 lines
1.2 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
class DllEntryPlugin {
constructor(context, entries, name) {
2016-12-29 16:33:01 +08:00
this.context = context;
this.entries = entries;
this.name = name;
}
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.name,
index: idx
};
2018-02-25 09:00:20 +08:00
return dep;
}),
this.name
),
this.name,
callback
);
2016-12-29 16:33:01 +08:00
});
}
}
module.exports = DllEntryPlugin;