This commit is contained in:
xiaoxiaojx 2025-09-23 01:08:53 +08:00
parent 018160e44d
commit daa38aa735
1 changed files with 9 additions and 7 deletions

View File

@ -122,6 +122,9 @@ class DotenvPlugin {
* @returns {void} * @returns {void}
*/ */
apply(compiler) { apply(compiler) {
/** @type {string[] | undefined} */
let fileDependenciesCache;
compiler.hooks.beforeCompile.tapAsync(PLUGIN_NAME, (_params, callback) => { compiler.hooks.beforeCompile.tapAsync(PLUGIN_NAME, (_params, callback) => {
const inputFileSystem = /** @type {InputFileSystem} */ ( const inputFileSystem = /** @type {InputFileSystem} */ (
compiler.inputFileSystem compiler.inputFileSystem
@ -133,21 +136,20 @@ class DotenvPlugin {
context, context,
(err, variables, fileDependencies) => { (err, variables, fileDependencies) => {
if (err) return callback(err); if (err) return callback(err);
if (fileDependencies) {
compiler.hooks.compilation.tap(PLUGIN_NAME, (compilation) => {
compilation.fileDependencies.addAll(fileDependencies);
});
}
const definitions = this.formatVariables(variables || {}); const definitions = this.formatVariables(variables || {});
const DefinePlugin = compiler.webpack.DefinePlugin; const DefinePlugin = compiler.webpack.DefinePlugin;
new DefinePlugin(definitions).apply(compiler); new DefinePlugin(definitions).apply(compiler);
fileDependenciesCache = fileDependencies;
callback(); callback();
} }
); );
}); });
compiler.hooks.compilation.tap(PLUGIN_NAME, (compilation) => {
compilation.fileDependencies.addAll(fileDependenciesCache || []);
});
} }
/** /**