NodeTemplatePlugin.js 1.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344
  1. /*
  2. MIT License http://www.opensource.org/licenses/mit-license.php
  3. Author Tobias Koppers @sokra
  4. */
  5. "use strict";
  6. const CommonJsChunkFormatPlugin = require("../javascript/CommonJsChunkFormatPlugin");
  7. const EnableChunkLoadingPlugin = require("../javascript/EnableChunkLoadingPlugin");
  8. /** @typedef {import("../Compiler")} Compiler */
  9. /**
  10. * Represents the node template plugin runtime component.
  11. * @typedef {object} NodeTemplatePluginOptions
  12. * @property {boolean=} asyncChunkLoading enable async chunk loading
  13. */
  14. class NodeTemplatePlugin {
  15. /**
  16. * Creates an instance of NodeTemplatePlugin.
  17. * @param {NodeTemplatePluginOptions=} options options object
  18. */
  19. constructor(options = {}) {
  20. /** @type {NodeTemplatePluginOptions} */
  21. this._options = options;
  22. }
  23. /**
  24. * Applies the plugin by registering its hooks on the compiler.
  25. * @param {Compiler} compiler the compiler instance
  26. * @returns {void}
  27. */
  28. apply(compiler) {
  29. const chunkLoading = this._options.asyncChunkLoading
  30. ? "async-node"
  31. : "require";
  32. compiler.options.output.chunkLoading = chunkLoading;
  33. new CommonJsChunkFormatPlugin().apply(compiler);
  34. new EnableChunkLoadingPlugin(chunkLoading).apply(compiler);
  35. }
  36. }
  37. module.exports = NodeTemplatePlugin;