[6a3a178] | 1 | /*
|
---|
| 2 | MIT License http://www.opensource.org/licenses/mit-license.php
|
---|
| 3 | Author Tobias Koppers @sokra
|
---|
| 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 | /** @typedef {import("../../declarations/WebpackOptions").InfrastructureLogging} InfrastructureLogging */
|
---|
| 15 | /** @typedef {import("../Compiler")} Compiler */
|
---|
| 16 |
|
---|
| 17 | class NodeEnvironmentPlugin {
|
---|
| 18 | /**
|
---|
| 19 | * @param {Object} options options
|
---|
| 20 | * @param {InfrastructureLogging} options.infrastructureLogging infrastructure logging options
|
---|
| 21 | */
|
---|
| 22 | constructor(options) {
|
---|
| 23 | this.options = options;
|
---|
| 24 | }
|
---|
| 25 |
|
---|
| 26 | /**
|
---|
| 27 | * Apply the plugin
|
---|
| 28 | * @param {Compiler} compiler the compiler instance
|
---|
| 29 | * @returns {void}
|
---|
| 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;
|
---|