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

View File

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