EntryOptionPlugin.js 1020 B

12345678910111213141516171819202122232425262728293031
  1. /*
  2. MIT License http://www.opensource.org/licenses/mit-license.php
  3. Author Tobias Koppers @sokra
  4. */
  5. "use strict";
  6. const SingleEntryPlugin = require("./SingleEntryPlugin");
  7. const MultiEntryPlugin = require("./MultiEntryPlugin");
  8. const DynamicEntryPlugin = require("./DynamicEntryPlugin");
  9. module.exports = class EntryOptionPlugin {
  10. apply(compiler) {
  11. compiler.plugin("entry-option", (context, entry) => {
  12. function itemToPlugin(item, name) {
  13. if(Array.isArray(item)) {
  14. return new MultiEntryPlugin(context, item, name);
  15. } else {
  16. return new SingleEntryPlugin(context, item, name);
  17. }
  18. }
  19. if(typeof entry === "string" || Array.isArray(entry)) {
  20. compiler.apply(itemToPlugin(entry, "main"));
  21. } else if(typeof entry === "object") {
  22. Object.keys(entry).forEach(name => compiler.apply(itemToPlugin(entry[name], name)));
  23. } else if(typeof entry === "function") {
  24. compiler.apply(new DynamicEntryPlugin(context, entry));
  25. }
  26. return true;
  27. });
  28. }
  29. };