Having trouble writing a plugin

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;
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?

Author: Fantashit

3 thoughts on “Having trouble writing a plugin

  1. 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.

Comments are closed.