Inject.addModuleRule
Inject.addModuleRule(matchesId, rule, options);
This function allows you to add a rule to transform one module ID into another.
Consider using Inject.addPackage if you would like to make a module globally available.
Examples
// let's say you moved a module, but don't want to
// update all the require() statements
Inject.addModuleRule(/myold\/modulePath/, function(id) {
return 'mynew/modulePath';
});
matchesId
The matchesId
parameter can either be a string or a regex. If a string, an exact match on module ID is required in order for the rule to be ran. If matchesId
is a regular expression, this expression will be tested against the Module ID.
rule
The rule object is either a string or a function. If a string, a 1:1 replacement is made on the matching Module ID. No history of previous transformations is saved. If rule
is a function, it takes one argument moduleId
and must return a string representing the transformed Module ID.
options
A collection of options for this rule. Supported options are:
- weight: assign a weight to this rule. Larger numbered rules run first.
- last: a boolean that, if true, will prevent further rules from running.
The family of rules Inject supports: