You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

44 lines
1.3 KiB

4 years ago
  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. const createConsoleLogger = require("../logging/createConsoleLogger");
  11. const nodeConsole = require("./nodeConsole");
  12. class NodeEnvironmentPlugin {
  13. constructor(options) {
  14. this.options = options || {};
  15. }
  16. apply(compiler) {
  17. compiler.infrastructureLogger = createConsoleLogger(
  18. Object.assign(
  19. {
  20. level: "info",
  21. debug: false,
  22. console: nodeConsole
  23. },
  24. this.options.infrastructureLogging
  25. )
  26. );
  27. compiler.inputFileSystem = new CachedInputFileSystem(
  28. new NodeJsInputFileSystem(),
  29. 60000
  30. );
  31. const inputFileSystem = compiler.inputFileSystem;
  32. compiler.outputFileSystem = new NodeOutputFileSystem();
  33. compiler.watchFileSystem = new NodeWatchFileSystem(
  34. compiler.inputFileSystem
  35. );
  36. compiler.hooks.beforeRun.tap("NodeEnvironmentPlugin", compiler => {
  37. if (compiler.inputFileSystem === inputFileSystem) inputFileSystem.purge();
  38. });
  39. }
  40. }
  41. module.exports = NodeEnvironmentPlugin;