-
-
Notifications
You must be signed in to change notification settings - Fork 605
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
4 changed files
with
107 additions
and
88 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,53 @@ | ||
const { packageExists } = require('../utils/package-exists'); | ||
const webpack = packageExists('webpack') ? require('webpack') : undefined; | ||
const logger = require('../utils/logger'); | ||
|
||
const PluginName = 'webpack-cli'; | ||
|
||
class WebpackCLIPlugin { | ||
constructor(options) { | ||
this.options = options; | ||
} | ||
async apply(compiler) { | ||
const compilers = compiler.compilers || [compiler]; | ||
|
||
for (const compiler of compilers) { | ||
if (this.options.progress) { | ||
const { ProgressPlugin } = compiler.webpack || webpack; | ||
|
||
let progressPluginExists; | ||
|
||
if (compiler.options.plugins) { | ||
progressPluginExists = Boolean(compiler.options.plugins.find((e) => e instanceof ProgressPlugin)); | ||
} | ||
|
||
if (!progressPluginExists) { | ||
new ProgressPlugin().apply(compiler); | ||
} | ||
} | ||
} | ||
|
||
const compilationName = (compilation) => (compilation.name ? ` ${compilation.name}` : ''); | ||
|
||
compiler.hooks.watchRun.tap(PluginName, (compilation) => { | ||
const { bail, watch } = compilation.options; | ||
if (bail && watch) { | ||
logger.warn('You are using "bail" with "watch". "bail" will still exit webpack when the first error is found.'); | ||
} | ||
|
||
logger.success(`Compilation${compilationName(compilation)} starting...`); | ||
}); | ||
|
||
compiler.hooks.done.tap(PluginName, (compilation) => { | ||
logger.success(`Compilation${compilationName(compilation)} finished`); | ||
|
||
process.nextTick(() => { | ||
if (compiler.watchMode) { | ||
logger.success('watching files for updates...'); | ||
} | ||
}); | ||
}); | ||
} | ||
} | ||
|
||
module.exports = WebpackCLIPlugin; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters