DllEntryPlugin.js 1.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354
  1. /*
  2. MIT License http://www.opensource.org/licenses/mit-license.php
  3. Author Tobias Koppers @sokra
  4. */
  5. "use strict";
  6. const DllEntryDependency = require("./dependencies/DllEntryDependency");
  7. const SingleEntryDependency = require("./dependencies/SingleEntryDependency");
  8. const DllModuleFactory = require("./DllModuleFactory");
  9. class DllEntryPlugin {
  10. constructor(context, entries, name) {
  11. this.context = context;
  12. this.entries = entries;
  13. this.name = name;
  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. SingleEntryDependency,
  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 SingleEntryDependency(e);
  36. dep.loc = {
  37. name: this.name,
  38. index: idx
  39. };
  40. return dep;
  41. }),
  42. this.name
  43. ),
  44. this.name,
  45. callback
  46. );
  47. });
  48. }
  49. }
  50. module.exports = DllEntryPlugin;