JsonpTemplatePlugin.js 1.3 KB

123456789101112131415161718192021222324252627282930313233343536373839
  1. /*
  2. MIT License http://www.opensource.org/licenses/mit-license.php
  3. Author Tobias Koppers @sokra
  4. */
  5. "use strict";
  6. const ArrayPushCallbackChunkFormatPlugin = require("../javascript/ArrayPushCallbackChunkFormatPlugin");
  7. const EnableChunkLoadingPlugin = require("../javascript/EnableChunkLoadingPlugin");
  8. const JsonpChunkLoadingRuntimeModule = require("./JsonpChunkLoadingRuntimeModule");
  9. /** @typedef {import("../Compilation")} Compilation */
  10. /** @typedef {import("../Compiler")} Compiler */
  11. // TODO webpack 6 remove this class
  12. class JsonpTemplatePlugin {
  13. /**
  14. * Returns hooks.
  15. * @deprecated use JsonpChunkLoadingRuntimeModule.getCompilationHooks instead
  16. * @param {Compilation} compilation the compilation
  17. * @returns {JsonpChunkLoadingRuntimeModule.JsonpCompilationPluginHooks} hooks
  18. */
  19. static getCompilationHooks(compilation) {
  20. return JsonpChunkLoadingRuntimeModule.getCompilationHooks(compilation);
  21. }
  22. /**
  23. * Applies the plugin by registering its hooks on the compiler.
  24. * @param {Compiler} compiler the compiler instance
  25. * @returns {void}
  26. */
  27. apply(compiler) {
  28. compiler.options.output.chunkLoading = "jsonp";
  29. new ArrayPushCallbackChunkFormatPlugin().apply(compiler);
  30. new EnableChunkLoadingPlugin("jsonp").apply(compiler);
  31. }
  32. }
  33. module.exports = JsonpTemplatePlugin;