NodeEnvironmentPlugin.js 959 B

12345678910111213141516171819202122232425262728
  1. /*
  2. MIT License http://www.opensource.org/licenses/mit-license.php
  3. Author Tobias Koppers @sokra
  4. */
  5. "use strict";
  6. const NodeWatchFileSystem = require("./NodeWatchFileSystem");
  7. const NodeOutputFileSystem = require("./NodeOutputFileSystem");
  8. const NodeJsInputFileSystem = require("enhanced-resolve/lib/NodeJsInputFileSystem");
  9. const CachedInputFileSystem = require("enhanced-resolve/lib/CachedInputFileSystem");
  10. class NodeEnvironmentPlugin {
  11. apply(compiler) {
  12. compiler.inputFileSystem = new CachedInputFileSystem(
  13. new NodeJsInputFileSystem(),
  14. 60000
  15. );
  16. const inputFileSystem = compiler.inputFileSystem;
  17. compiler.outputFileSystem = new NodeOutputFileSystem();
  18. compiler.watchFileSystem = new NodeWatchFileSystem(
  19. compiler.inputFileSystem
  20. );
  21. compiler.hooks.beforeRun.tap("NodeEnvironmentPlugin", compiler => {
  22. if (compiler.inputFileSystem === inputFileSystem) inputFileSystem.purge();
  23. });
  24. }
  25. }
  26. module.exports = NodeEnvironmentPlugin;