webpack/lib/EntryOptionPlugin.js

34 lines
1023 B
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
2017-08-09 08:50:10 +08:00
*/
"use strict";
2015-05-17 00:27:59 +08:00
const SingleEntryPlugin = require("./SingleEntryPlugin");
const MultiEntryPlugin = require("./MultiEntryPlugin");
const DynamicEntryPlugin = require("./DynamicEntryPlugin");
2015-05-17 00:27:59 +08:00
2017-11-08 18:32:05 +08:00
const itemToPlugin = (context, item, name) => {
if(Array.isArray(item)) {
return new MultiEntryPlugin(context, item, name);
}
2017-08-09 08:50:10 +08:00
return new SingleEntryPlugin(context, item, name);
2017-11-08 18:32:05 +08:00
};
module.exports = class EntryOptionPlugin {
apply(compiler) {
2017-12-08 15:00:32 +08:00
compiler.hooks.entryOption.tap("EntryOptionPlugin", (context, entry) => {
if(typeof entry === "string" || Array.isArray(entry)) {
itemToPlugin(context, entry, "main").apply(compiler);
} else if(typeof entry === "object") {
2018-01-22 20:52:43 +08:00
for(const name of Object.keys(entry)) {
itemToPlugin(context, entry[name], name).apply(compiler);
}
} else if(typeof entry === "function") {
new DynamicEntryPlugin(context, entry).apply(compiler);
}
return true;
});
}
2017-01-11 17:51:58 +08:00
};