clean-terminal-webpack-plugin
Advanced tools
Comparing version 1.1.0 to 2.0.0
27
index.js
@@ -1,6 +0,8 @@ | ||
"use strict"; | ||
'use strict'; | ||
class CleanTerminalPlugin { | ||
constructor(options = {}) { | ||
this.message = options.message; | ||
const {message, onlyInWatchMode = true} = options; | ||
this.message = message; | ||
this.onlyInWatchMode = onlyInWatchMode; | ||
} | ||
@@ -10,9 +12,9 @@ | ||
if (compiler.hooks) { | ||
compiler.hooks.afterCompile.tap("CleanTerminalPlugin", () => { | ||
if (process.env.NODE_ENV !== "production") this.clearConsole(); | ||
compiler.hooks.afterCompile.tap('CleanTerminalPlugin', () => { | ||
if (this.shouldClearConsole(compiler)) this.clearConsole(); | ||
}); | ||
} else { | ||
// backwards compatible version of compiler.hooks | ||
compiler.plugin("emit", (_, done) => { | ||
if (process.env.NODE_ENV !== "production") this.clearConsole(); | ||
compiler.plugin('emit', (_, done) => { | ||
if (this.shouldClearConsole()) this.clearConsole(); | ||
done(); | ||
@@ -23,5 +25,14 @@ }); | ||
shouldClearConsole(compiler) { | ||
if (this.onlyInWatchMode) return compile.watchMode; | ||
else | ||
return ( | ||
process.env.NODE_ENV !== 'production' && | ||
process.env.options.mode !== 'production' | ||
); | ||
} | ||
clearConsole() { | ||
const clear = "\x1B[2J\x1B[3J\x1B[H"; | ||
const output = this.message ? clear + this.message + "\n\n" : clear; | ||
const clear = '\x1B[2J\x1B[3J\x1B[H'; | ||
const output = this.message ? clear + this.message + '\n\n' : clear; | ||
process.stdout.write(output); | ||
@@ -28,0 +39,0 @@ } |
{ | ||
"name": "clean-terminal-webpack-plugin", | ||
"version": "1.1.0", | ||
"version": "2.0.0", | ||
"description": "Cleans your terminal output during development to only show the latest build information.", | ||
@@ -5,0 +5,0 @@ "main": "index.js", |
@@ -30,5 +30,6 @@ # Clean Terminal Webpack Plugin | ||
| key | type | required | description | | ||
| --- | --- | --- | --- | | ||
| message | String | false | Message to be printend. | | ||
| key | type | required | defaults | description | | ||
| --- | --- | --- | --- | --- | | ||
| message | String | no | `undefined` | Message to be printed | | ||
| onlyInWatchMode | Boolean | no | `true` | Only clear the screen if webpack is in watch mode | | ||
@@ -47,6 +48,7 @@ ## Example | ||
new CleanTerminalPlugin({ | ||
message: `dev server running on http://${HOST}:${PORT}` | ||
message: `dev server running on http://${HOST}:${PORT}`, | ||
onlyInWatchMode: false | ||
}) | ||
] | ||
}; | ||
``` | ||
``` |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
4147
35
53