Created
August 5, 2017 16:26
-
-
Save maxkoretskyi/2bc8fee0f58f6b78ae62cd2d4695d635 to your computer and use it in GitHub Desktop.
This file contains hidden or 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
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