NodeTemplatePlugin.js 848 B

123456789101112131415161718192021222324252627282930313233
  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. class NodeTemplatePlugin {
  10. constructor(options) {
  11. this._options = options || {};
  12. }
  13. /**
  14. * Apply the plugin
  15. * @param {Compiler} compiler the compiler instance
  16. * @returns {void}
  17. */
  18. apply(compiler) {
  19. const chunkLoading = this._options.asyncChunkLoading
  20. ? "async-node"
  21. : "require";
  22. compiler.options.output.chunkLoading = chunkLoading;
  23. new CommonJsChunkFormatPlugin().apply(compiler);
  24. new EnableChunkLoadingPlugin(chunkLoading).apply(compiler);
  25. }
  26. }
  27. module.exports = NodeTemplatePlugin;