diff --git a/src/plugin.js b/src/plugin.js index 1c72a04..14bdd1a 100644 --- a/src/plugin.js +++ b/src/plugin.js @@ -2,7 +2,7 @@ import { ProgressPlugin } from 'webpack'; import env from 'std-env'; import prettyTime from 'pretty-time'; -import { startCase } from './utils'; +import { startCase, shortenPath } from './utils'; import * as reporters from './reporters'; // eslint-disable-line import/no-namespace import { parseRequest, hook } from './utils/webpack'; @@ -149,6 +149,15 @@ export default class WebpackBarPlugin extends ProgressPlugin { this.callReporters('start'); }); + // Watch compilation has been invalidated. + hook(compiler, 'invalid', (fileName, changeTime) => { + this.callReporters('change', { + path: fileName, + shortPath: shortenPath(fileName), + time: changeTime, + }); + }); + // Compilation has completed hook(compiler, 'done', (stats) => { const time = prettyTime(process.hrtime(this.state.start), 2); diff --git a/src/reporters/basic.js b/src/reporters/basic.js index 457ff26..1cae766 100644 --- a/src/reporters/basic.js +++ b/src/reporters/basic.js @@ -5,6 +5,10 @@ export default class SimpleReporter { consola.info(`Compiling ${context.state.name}`); } + change(context, { shortPath }) { + consola.info(`${shortPath} changed.`, `Rebuilding ${context.state.name}`); + } + done(context) { const { hasError, message, name } = context.state; consola[hasError ? 'error' : 'success'](`${name}: ${message}`); diff --git a/src/utils/index.js b/src/utils/index.js index 7d6efb6..8ceb4f5 100644 --- a/src/utils/index.js +++ b/src/utils/index.js @@ -1,3 +1,5 @@ +import { sep } from 'path'; + export function first(arr) { return arr[0]; } @@ -27,10 +29,15 @@ export function removeBefore(delimiter, str) { return last(str.split(delimiter)) || ''; } -export const range = (len) => { +export function range(len) { const arr = []; for (let i = 0; i < len; i++) { arr.push(i); } return arr; -}; +} + +export function shortenPath(path = '') { + const cwd = process.cwd() + sep; + return path.replace(cwd, ''); +}