1 |
|
2 |
|
3 |
|
4 |
|
5 |
|
6 | "use strict";
|
7 |
|
8 | const CachedInputFileSystem = require("enhanced-resolve/lib/CachedInputFileSystem");
|
9 | const fs = require("graceful-fs");
|
10 | const createConsoleLogger = require("../logging/createConsoleLogger");
|
11 | const NodeWatchFileSystem = require("./NodeWatchFileSystem");
|
12 | const nodeConsole = require("./nodeConsole");
|
13 |
|
14 |
|
15 |
|
16 |
|
17 | class NodeEnvironmentPlugin {
|
18 | |
19 |
|
20 |
|
21 |
|
22 | constructor(options) {
|
23 | this.options = options;
|
24 | }
|
25 |
|
26 | |
27 |
|
28 |
|
29 |
|
30 |
|
31 | apply(compiler) {
|
32 | const { infrastructureLogging } = this.options;
|
33 | compiler.infrastructureLogger = createConsoleLogger({
|
34 | level: infrastructureLogging.level || "info",
|
35 | debug: infrastructureLogging.debug || false,
|
36 | console:
|
37 | infrastructureLogging.console ||
|
38 | nodeConsole({
|
39 | colors: infrastructureLogging.colors,
|
40 | appendOnly: infrastructureLogging.appendOnly,
|
41 | stream: infrastructureLogging.stream
|
42 | })
|
43 | });
|
44 | compiler.inputFileSystem = new CachedInputFileSystem(fs, 60000);
|
45 | const inputFileSystem = compiler.inputFileSystem;
|
46 | compiler.outputFileSystem = fs;
|
47 | compiler.intermediateFileSystem = fs;
|
48 | compiler.watchFileSystem = new NodeWatchFileSystem(
|
49 | compiler.inputFileSystem
|
50 | );
|
51 | compiler.hooks.beforeRun.tap("NodeEnvironmentPlugin", compiler => {
|
52 | if (compiler.inputFileSystem === inputFileSystem) {
|
53 | compiler.fsStartTime = Date.now();
|
54 | inputFileSystem.purge();
|
55 | }
|
56 | });
|
57 | }
|
58 | }
|
59 |
|
60 | module.exports = NodeEnvironmentPlugin;
|