WebWorkerChunkTemplatePlugin.js 950 B

1234567891011121314151617181920212223242526272829
  1. /*
  2. MIT License http://www.opensource.org/licenses/mit-license.php
  3. Author Tobias Koppers @sokra
  4. */
  5. "use strict";
  6. var ConcatSource = require("webpack-sources").ConcatSource;
  7. var Template = require("../Template");
  8. class WebWorkerChunkTemplatePlugin {
  9. apply(chunkTemplate) {
  10. chunkTemplate.plugin("render", function(modules, chunk) {
  11. const chunkCallbackName = this.outputOptions.chunkCallbackName || Template.toIdentifier("webpackChunk" + (this.outputOptions.library || ""));
  12. const source = new ConcatSource();
  13. source.add(`${chunkCallbackName}(${JSON.stringify(chunk.ids)},`);
  14. source.add(modules);
  15. source.add(")");
  16. return source;
  17. });
  18. chunkTemplate.plugin("hash", function(hash) {
  19. hash.update("webworker");
  20. hash.update("3");
  21. hash.update(`${this.outputOptions.chunkCallbackName}`);
  22. hash.update(`${this.outputOptions.library}`);
  23. });
  24. }
  25. }
  26. module.exports = WebWorkerChunkTemplatePlugin;