You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

37 lines
837 B

4 years ago
  1. /*
  2. MIT License http://www.opensource.org/licenses/mit-license.php
  3. Author Tobias Koppers @sokra
  4. */
  5. "use strict";
  6. const PrefetchDependency = require("./dependencies/PrefetchDependency");
  7. class PrefetchPlugin {
  8. constructor(context, request) {
  9. if (!request) {
  10. this.request = context;
  11. } else {
  12. this.context = context;
  13. this.request = request;
  14. }
  15. }
  16. apply(compiler) {
  17. compiler.hooks.compilation.tap(
  18. "PrefetchPlugin",
  19. (compilation, { normalModuleFactory }) => {
  20. compilation.dependencyFactories.set(
  21. PrefetchDependency,
  22. normalModuleFactory
  23. );
  24. }
  25. );
  26. compiler.hooks.make.tapAsync("PrefetchPlugin", (compilation, callback) => {
  27. compilation.prefetch(
  28. this.context || compiler.context,
  29. new PrefetchDependency(this.request),
  30. callback
  31. );
  32. });
  33. }
  34. }
  35. module.exports = PrefetchPlugin;