Dependency Management Got Awesome
CommonJS and AMD Compliant dependency loader for modern web apps
Inject.addFileRule
0.7.x
Inject.addFileRule(matchesPath, rule, options);
This function allows you to add a rule to transform one path into another during the loading process when a Module ID is associated with a URL.
Examples
// if a path contains "nocache", use a different url
Inject.addFileRule(/^https?:]\/\/.*?nocache.*?$/, function(path) {
return path.replace(/www\.mysite\.com/, 'www.my-nocached-site.com');
}, { weight: 0 });
matchesPath
The matchesPath
parameter can either be a string or a regex. If a string, an exact match on the path is required in order to perform a transformation. If matchesPath
is a regular expression, then the path is tested against the regex.
rule
The rule object is either a string or a function. If a string, a 1:1 replacement is made on the matching path. No history of previous transformations is saved. If rule
is a function, it takes one argument path
and must return a string representing the transformed path.
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: