I have a plugin:
var Foo = function() {};
Foo.prototype.apply = function() {
compiler.plugin(‘compilation’, function(compilation, params) {
compilation.dependencyFactories.set(ConstDependency, new NullFactory());
compilation.dependencyTemplates.set(ConstDependency, new ConstDependency.Template());
});
compiler.parser.plugin(‘call abc.bar’, function(expr) {
var param = this.evaluateExpression(expr.arguments[0]);
var dep = new ConstDependency(JSON.stringify(“something else”), expr.range);
dep.loc = expr.loc;
this.state.current.addDependency(dep);
return true;
});
}
–> When I run it against this file:
var someString = abc.bar(‘something’);
–> It gets compiled and replaced with:
var someString = ‘something else’;
–> But when I do this:
var abc = require(‘abc’);
var someString = abc.bar(‘something’);
–> It gets compiled to:
var abc = webpack_require(123);
var someString = abc.bar(‘something’);
What’s happening and why does the compiler behave differently when you have a local variable?
And how do I make it so the replacement still happens?
This issue had no activity for at least half a year.
It’s subject to automatic issue closing if there is no activity in the next 15 days.
Please read official docs about writing plugins👍
Official docs: https://webpack.js.org/contribute/writing-a-plugin/