webpack/lib/node/NodeEnvironmentPlugin.js

40 lines
1.1 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
*/
2018-07-30 23:08:51 +08:00
"use strict";
2013-01-31 01:49:25 +08:00
const CachedInputFileSystem = require("enhanced-resolve/lib/CachedInputFileSystem");
2018-07-30 23:08:51 +08:00
const NodeJsInputFileSystem = require("enhanced-resolve/lib/NodeJsInputFileSystem");
const fs = require("graceful-fs");
2018-07-30 23:08:51 +08:00
const NodeWatchFileSystem = require("./NodeWatchFileSystem");
2018-11-09 05:59:19 +08:00
/** @typedef {import("../Compiler")} Compiler */
class NodeEnvironmentPlugin {
2018-11-09 05:59:19 +08:00
/**
* @param {Compiler} compiler the compiler instance
* @returns {void}
*/
apply(compiler) {
2018-02-25 09:00:20 +08:00
compiler.inputFileSystem = new CachedInputFileSystem(
new NodeJsInputFileSystem(),
60000
);
const inputFileSystem = compiler.inputFileSystem;
compiler.outputFileSystem = fs;
compiler.intermediateFileSystem = fs;
2018-02-25 09:00:20 +08:00
compiler.watchFileSystem = new NodeWatchFileSystem(
compiler.inputFileSystem
);
compiler.hooks.beforeRun.tap("NodeEnvironmentPlugin", compiler => {
2018-11-09 05:59:19 +08:00
if (compiler.inputFileSystem === inputFileSystem) {
inputFileSystem.purge();
}
});
}
}
2018-11-09 05:59:19 +08:00
2013-01-31 01:49:25 +08:00
module.exports = NodeEnvironmentPlugin;