Dependency Management Got Awesome CommonJS and AMD Compliant dependency loader for modern web apps

Inject.addFileRule

0.5.x

OLD: This is an old version of documentation. You probably want the most recent version of this document, from the sidebar on the right.
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:

comments powered by Disqus