Skip to content

Commit

Permalink
feat(tags): reordered all things
Browse files Browse the repository at this point in the history
  • Loading branch information
TheLarkInn committed Mar 28, 2017
1 parent c03027f commit 6a697d8
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 6 deletions.
28 changes: 24 additions & 4 deletions plugin-lessons-plugins/2CompilerWebpackPlugin.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
* Just some custom plugin utility(s) I wrote.
*/
const pluginUtils = require("./plugin-utils");
const chalk = require("chalk");

/**
* @class CompilerWebpackPlugin - This is a example of a webpack plugin using `class`. The most common and easy to understand syntax
Expand All @@ -24,16 +25,35 @@ class CompilerWebpackPlugin {
* @memberOf CompilerWebpackPlugin
*/
apply(compiler) {
compiler.plugin(["run", "watch-run"], (compiler, callback) => {
pluginUtils.logPluginEvent(`${this.message}`, "CompilerWebpackPlugin");
/**
* @param {Compiler} compiler - The Compiler Instance (self)
* @param {Function} callback - callback which signals the hook is finished and that webpack can continue to next compilation step ()
* @description "before-run" - Runs before the compiler begins any compilation process.
*
*/
compiler.plugin("before-run", (compiler, callback) => {
pluginUtils.logPluginEvent("compiler:before-run", "CompilerWebpackPlugin", "bgMagenta");
callback();
});

compiler.plugin(["run", "watch-run"], (compiler, callback) => {
pluginUtils.logPluginEvent(`${this.message}`, "CompilerWebpackPlugin");
callback();
});

compiler.plugin("failed", (error) => {
pluginUtils.logPluginEvent("compiler:failed","CompilerWebpackPlugin", "bgRed");
});

compiler.plugin("done", (stats/*: Stats*/) => {
// console.log(stats); <=== always keep a console.log or node inspector handy so you can follow the flow of source through the plugin system.
// debugger <= The "done" event ssends to parent top ctrl,
const moduleString = stats.toJson().modules.map(module => module.identifier).join(`\n`);


callback();
pluginUtils.logPluginEvent(`compiler:done\n${moduleString}`, "CompilerWebpackPlugin", "bgGreen");
});
}
}


module.exports = CompilerWebpackPlugin;
4 changes: 2 additions & 2 deletions plugin-lessons-plugins/plugin-utils.js
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
const chalk = require("chalk");

module.exports = {
logPluginEvent: function(eventName, pluginName) {
console.log(chalk.black(chalk.bgCyan(
logPluginEvent: function(eventName, pluginName, backgroundColor = "bgCyan") {
console.log(chalk.black(chalk[backgroundColor](
`
${chalk.bold(chalk.white("WEBPACK PLUGIN EVENT"))}
Expand Down

0 comments on commit 6a697d8

Please sign in to comment.