NodeTemplatePlugin.js 1.0 KB

1234567891011121314151617181920212223242526272829303132333435363738394041
  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. this._options = options;
  19. }
  20. /**
  21. * Apply the plugin
  22. * @param {Compiler} compiler the compiler instance
  23. * @returns {void}
  24. */
  25. apply(compiler) {
  26. const chunkLoading = this._options.asyncChunkLoading
  27. ? "async-node"
  28. : "require";
  29. compiler.options.output.chunkLoading = chunkLoading;
  30. new CommonJsChunkFormatPlugin().apply(compiler);
  31. new EnableChunkLoadingPlugin(chunkLoading).apply(compiler);
  32. }
  33. }
  34. module.exports = NodeTemplatePlugin;