I'm working on building a test webpack plugin. I have the following code:
module.exports = class TestPlugin{
constructor(options){
this.options = options;
}
apply(compiler){
compiler.plugin("emit", function(){
console.log(this.options);
})
}
}
in my webpack.config.js file I have the following:
const TestPlugin = require('./plugins/TestPlugin');
...
plugins: [
new TestPlugin({
testOption:'testing option'
}),
...
The issue is that it's printing "undefined" instead of the option object. I put a console.log in the constructor and I get the proper result:
{testOption:'testing option'}
but I can't seem to access it in the apply method, and it returns undefined. What am I doing wrong that I can't access this content? I tried changing "emit" to other things like "done" and I still get the same result.