DllEntryPlugin.js 1.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455
  1. /*
  2. MIT License http://www.opensource.org/licenses/mit-license.php
  3. Author Tobias Koppers @sokra
  4. */
  5. "use strict";
  6. const DllModuleFactory = require("./DllModuleFactory");
  7. const DllEntryDependency = require("./dependencies/DllEntryDependency");
  8. const EntryDependency = require("./dependencies/EntryDependency");
  9. class DllEntryPlugin {
  10. constructor(context, entries, options) {
  11. this.context = context;
  12. this.entries = entries;
  13. this.options = options;
  14. }
  15. apply(compiler) {
  16. compiler.hooks.compilation.tap(
  17. "DllEntryPlugin",
  18. (compilation, { normalModuleFactory }) => {
  19. const dllModuleFactory = new DllModuleFactory();
  20. compilation.dependencyFactories.set(
  21. DllEntryDependency,
  22. dllModuleFactory
  23. );
  24. compilation.dependencyFactories.set(
  25. EntryDependency,
  26. normalModuleFactory
  27. );
  28. }
  29. );
  30. compiler.hooks.make.tapAsync("DllEntryPlugin", (compilation, callback) => {
  31. compilation.addEntry(
  32. this.context,
  33. new DllEntryDependency(
  34. this.entries.map((e, idx) => {
  35. const dep = new EntryDependency(e);
  36. dep.loc = {
  37. name: this.options.name,
  38. index: idx
  39. };
  40. return dep;
  41. }),
  42. this.options.name
  43. ),
  44. this.options,
  45. callback
  46. );
  47. });
  48. }
  49. }
  50. module.exports = DllEntryPlugin;