webpack/lib/node/NodeTemplatePlugin.js

42 lines
1.0 KiB
JavaScript
Raw Normal View History

2013-01-31 01:49:25 +08:00
/*
MIT License http://www.opensource.org/licenses/mit-license.php
Author Tobias Koppers @sokra
*/
"use strict";
const CommonJsChunkFormatPlugin = require("../javascript/CommonJsChunkFormatPlugin");
const EnableChunkLoadingPlugin = require("../javascript/EnableChunkLoadingPlugin");
2018-11-09 05:59:19 +08:00
/** @typedef {import("../Compiler")} Compiler */
2023-05-26 02:31:28 +08:00
/**
2024-06-11 21:09:50 +08:00
* @typedef {object} NodeTemplatePluginOptions
2025-04-16 22:04:11 +08:00
* @property {boolean=} asyncChunkLoading enable async chunk loading
2023-05-26 02:31:28 +08:00
*/
class NodeTemplatePlugin {
2023-05-26 02:31:28 +08:00
/**
2025-04-16 22:04:11 +08:00
* @param {NodeTemplatePluginOptions=} options options object
2023-05-26 02:31:28 +08:00
*/
2023-05-26 03:29:51 +08:00
constructor(options = {}) {
this._options = options;
}
2018-11-09 05:59:19 +08:00
/**
2020-04-23 16:48:36 +08:00
* Apply the plugin
2018-11-09 05:59:19 +08:00
* @param {Compiler} compiler the compiler instance
* @returns {void}
*/
apply(compiler) {
const chunkLoading = this._options.asyncChunkLoading
? "async-node"
: "require";
compiler.options.output.chunkLoading = chunkLoading;
new CommonJsChunkFormatPlugin().apply(compiler);
new EnableChunkLoadingPlugin(chunkLoading).apply(compiler);
}
2013-01-31 01:49:25 +08:00
}
2013-03-01 16:44:58 +08:00
module.exports = NodeTemplatePlugin;