2013-01-31 01:49:25 +08:00
|
|
|
/*
|
|
|
|
MIT License http://www.opensource.org/licenses/mit-license.php
|
|
|
|
Author Tobias Koppers @sokra
|
|
|
|
*/
|
|
|
|
|
2017-01-08 00:06:08 +08:00
|
|
|
"use strict";
|
|
|
|
|
2020-08-25 16:30:56 +08:00
|
|
|
const CommonJsChunkFormatPlugin = require("../javascript/CommonJsChunkFormatPlugin");
|
2020-08-26 03:45:56 +08:00
|
|
|
const EnableChunkLoadingPlugin = require("../javascript/EnableChunkLoadingPlugin");
|
2017-01-08 00:06:08 +08:00
|
|
|
|
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
|
|
|
*/
|
|
|
|
|
2017-01-08 00:06:08 +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;
|
2017-01-08 00:06:08 +08:00
|
|
|
}
|
|
|
|
|
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}
|
|
|
|
*/
|
2017-01-08 00:06:08 +08:00
|
|
|
apply(compiler) {
|
2020-08-26 03:45:56 +08:00
|
|
|
const chunkLoading = this._options.asyncChunkLoading
|
2020-08-25 19:37:40 +08:00
|
|
|
? "async-node"
|
|
|
|
: "require";
|
2020-08-26 03:45:56 +08:00
|
|
|
compiler.options.output.chunkLoading = chunkLoading;
|
2020-08-25 16:30:56 +08:00
|
|
|
new CommonJsChunkFormatPlugin().apply(compiler);
|
2020-08-26 03:45:56 +08:00
|
|
|
new EnableChunkLoadingPlugin(chunkLoading).apply(compiler);
|
2017-01-08 00:06:08 +08:00
|
|
|
}
|
2013-01-31 01:49:25 +08:00
|
|
|
}
|
2017-01-08 00:06:08 +08:00
|
|
|
|
2013-03-01 16:44:58 +08:00
|
|
|
module.exports = NodeTemplatePlugin;
|