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.

WebWorkerHotUpdateChunkTemplatePlugin.js 1.2KB

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