Skip to content

Instantly share code, notes, and snippets.

@maxkoretskyi
Created August 5, 2017 16:26
Show Gist options
  • Save maxkoretskyi/2bc8fee0f58f6b78ae62cd2d4695d635 to your computer and use it in GitHub Desktop.
Save maxkoretskyi/2bc8fee0f58f6b78ae62cd2d4695d635 to your computer and use it in GitHub Desktop.
const fs = require('fs');
const path = require('path');
class HelloWorldCheckerPlugin {
constructor(options) {
this.options = options;
}
apply(compiler) {
compiler.plugin('make', (compilation, cb) => this._make(compilation, cb));
}
_make(compilation, cb) {
try {
const file = fs.readFileSync(path.resolve('/', this.options.path), 'utf8');
if (file.includes('Hello World!')) {
console.log(`The file ${this.options.path} contains 'Hello World!' string`);
} else {
console.log(`The file ${this.options.path} doesn't contain 'Hello World!' string`)
}
cb();
} catch (e) {
compilation.errors.push(e);
cb();
}
}
}
exports.HelloWorldCheckerPlugin = HelloWorldCheckerPlugin;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment