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.

39 lines
1.0 KiB

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 { ConcatSource } = require("webpack-sources");
  7. class JsonpHotUpdateChunkTemplatePlugin {
  8. apply(hotUpdateChunkTemplate) {
  9. hotUpdateChunkTemplate.hooks.render.tap(
  10. "JsonpHotUpdateChunkTemplatePlugin",
  11. (modulesSource, modules, removedModules, hash, id) => {
  12. const source = new ConcatSource();
  13. source.add(
  14. `${
  15. hotUpdateChunkTemplate.outputOptions.hotUpdateFunction
  16. }(${JSON.stringify(id)},`
  17. );
  18. source.add(modulesSource);
  19. source.add(")");
  20. return source;
  21. }
  22. );
  23. hotUpdateChunkTemplate.hooks.hash.tap(
  24. "JsonpHotUpdateChunkTemplatePlugin",
  25. hash => {
  26. hash.update("JsonpHotUpdateChunkTemplatePlugin");
  27. hash.update("3");
  28. hash.update(
  29. `${hotUpdateChunkTemplate.outputOptions.hotUpdateFunction}`
  30. );
  31. hash.update(`${hotUpdateChunkTemplate.outputOptions.library}`);
  32. }
  33. );
  34. }
  35. }
  36. module.exports = JsonpHotUpdateChunkTemplatePlugin;