Skip to content

Improved CommonJS Support and Relative File Path Normalizing

Choose a tag to compare

@gfranko gfranko released this 14 Oct 22:37
· 211 commits to master since this release

With this release, there is now support for converting CommonJS require() variable declarations inside of define() modules. This can be extremely helpful when using the r.js cjsTranslate configuration option.

CommonJS

Here are a few examples:

This:

var x = require('third');

Becomes:

var x = third;

This:

var x = require('third').exampleProp;

Becomes:

var x = third.prop;

This:

var x = require('third').exampleProp();

Becomes:

var x = third.exampleProp();

Relative File Paths

Also, relative file paths are also now getting normalized to JavaScript-standard variable names.

This:

define('./someModule', function() {}

Becomes:

var someModule = function() {})();
define('../modules/someModule', function() {}

Becomes:

var modules_someModule = function() {})();