DllPlugin.js 1.1 KB

1234567891011121314151617181920212223242526272829303132333435363738
  1. /*
  2. MIT License http://www.opensource.org/licenses/mit-license.php
  3. Author Tobias Koppers @sokra
  4. */
  5. "use strict";
  6. const DllEntryPlugin = require("./DllEntryPlugin");
  7. const LibManifestPlugin = require("./LibManifestPlugin");
  8. const FlagInitialModulesAsUsedPlugin = require("./FlagInitialModulesAsUsedPlugin");
  9. class DllPlugin {
  10. constructor(options) {
  11. this.options = options;
  12. }
  13. apply(compiler) {
  14. compiler.plugin("entry-option", (context, entry) => {
  15. function itemToPlugin(item, name) {
  16. if(Array.isArray(item))
  17. return new DllEntryPlugin(context, item, name);
  18. else
  19. throw new Error("DllPlugin: supply an Array as entry");
  20. }
  21. if(typeof entry === "object" && !Array.isArray(entry)) {
  22. Object.keys(entry).forEach(name => {
  23. compiler.apply(itemToPlugin(entry[name], name));
  24. });
  25. } else {
  26. compiler.apply(itemToPlugin(entry, "main"));
  27. }
  28. return true;
  29. });
  30. compiler.apply(new LibManifestPlugin(this.options));
  31. compiler.apply(new FlagInitialModulesAsUsedPlugin());
  32. }
  33. }
  34. module.exports = DllPlugin;