NodeTemplatePlugin.js 1.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142
  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. * @typedef {object} NodeTemplatePluginOptions
  11. * @property {boolean=} asyncChunkLoading enable async chunk loading
  12. */
  13. class NodeTemplatePlugin {
  14. /**
  15. * @param {NodeTemplatePluginOptions=} options options object
  16. */
  17. constructor(options = {}) {
  18. /** @type {NodeTemplatePluginOptions} */
  19. this._options = options;
  20. }
  21. /**
  22. * Apply the plugin
  23. * @param {Compiler} compiler the compiler instance
  24. * @returns {void}
  25. */
  26. apply(compiler) {
  27. const chunkLoading = this._options.asyncChunkLoading
  28. ? "async-node"
  29. : "require";
  30. compiler.options.output.chunkLoading = chunkLoading;
  31. new CommonJsChunkFormatPlugin().apply(compiler);
  32. new EnableChunkLoadingPlugin(chunkLoading).apply(compiler);
  33. }
  34. }
  35. module.exports = NodeTemplatePlugin;