Releases: gfranko/amdclean
Bug Fixes and 4 New Options
Bug Fixes
- Conditional AMD checks were always getting cleaned. #28
New Options
- prefixMode - Allows you to decide whether you would like your module names normalized with underscores or the camel case convention
- prefixTransform - Function hook that gives users full control to write their own logic for how module names are transformed. #26
- removeModules - An array of module names that should be removed from the source (e.g. removing the RequireJS text! plugin from getting inlined) #29
- wrap - Similar functionality to the RequireJS
wrap
option. This was added for web apps that use theglobalObject
AMDClean option and theonModuleBundleComplete
RequireJS hook, but want the "global" object locally scoped. #31
Fixed Web Based Instances
Will now work correctly in web browsers (AMD or non-AMD)
New removeUseStricts Option and Minor Optimization Improvement
New removeUseStricts Option
- All
use strict
statements from your cleaned modules will now be removed by default. If you would like to keep them, then you must turn theremoveUseStricts
option tofalse
. Like this:
amdclean.clean({
'code': 'define("example", function() { "use strict"; var example = true; })',
'removeUseStricts': false
});
Optimization Improvement
- There has been a minor optimization improvement that will convert empty module definitions to
undefined
. For example:
AMD
define('example', function() {
});
Standard
var example = undefined;
Stable and Ready
After a few more minor bug fixes, AMDClean is now at version 1.0! It is ready for prime time and is already being used on a number of production applications/libraries. Enjoy =)
Love, Greg
Optimization and Bug Fixes
The 0.7.0
AMDClean release includes significant improvements/optimizations to the transpiling intelligence and a few small bug fixes. This means that your files will be even smaller than before. We are closing in on a 1.0.0 release people...
Transpiling Optimizations
define()
method transpiling has been dramatically optimized (#22). Here are a few examples:
AMD
define('example', [], function() {
return function(name) {
return 'Hello ' + name;
};
});
Standard
var example = function (name) {
return 'Hello ' + name;
};
AMD
define('example', [], function() {
return 'I love AMDClean';
});
Standard
var example = 'I love AMDClean';
AMD
define('example', function () {
'use strict';
return function (thing) {
return !isNaN(parseFloat(thing)) && isFinite(thing);
};
});
Standard
var example = function (thing) {
'use strict';
return !isNaN(parseFloat(thing)) && isFinite(thing);
};
Comments No Longer Stripped
- Source code comments will no longer be stripped by default (#23). If you would like comments to be stripped, then you can set the
escodegen
comment
option tofalse
. Like this:
amdclean.clean({
'code': 'define("example", function() { });',
'escodegen': { comment: false }
});
AMDClean for Web Apps
With the 0.6.0
release, AMDClean can now be reliably used to replace Almond.js in your web apps. Here are the changes that make this possible:
Converting Third-Party Libraries
Let's use jQuery as an example. In the jQuery source code, there is the following conditional AMD check to see if an AMD loader is being used:
// jQuery Source
if ( typeof define === "function" && define.amd ) {
define( "jquery", [], function() {
return jQuery;
});
}
AMDClean will now transform the jQuery source to this:
if ( true ) {
var jquery = function () {
return jQuery;
}();
}
Before version 0.6.0
, AMDClean would have left the AMD conditional if
statement alone, and would not know the return value for the jquery
module (causing a syntax error in your web app).
Correctly Transforming Define() Methods That Assume CommonJS support
Let's use the Esprima library as an example. Esprima uses the following syntax to conditionally check to see if an AMD loader is being used:
// Esprima Source
(function (root, factory) {
'use strict';
// Universal Module Definition (UMD) to support AMD, CommonJS/Node.js,
// Rhino, and plain browser loading.
if (typeof define === 'function' && define.amd) {
define(['exports'], factory);
} else if (typeof exports !== 'undefined') {
factory(exports);
} else {
factory((root.esprima = {}));
}
}(this, function (exports) {
// Esprima source code
// ...
// Does not return anything
}));
In the above code example, Esprima is conditionally defining an anonymous AMD module by passing the function identifier, factory
.
The factory
function that is being passed does not return any value inside of its function body, and instead just assigns properties to its exports
argument. It does this since it expects Require.js to automatically understand that it is using CommonJS syntax and to return the exports
argument as the module return value.
With the 0.6.0 release, AMDClean is now smart enough to correctly transform this conditional AMD definition. Here is how AMDClean now transforms the above code:
(function (root, factory) {
'use strict';
// Universal Module Definition (UMD) to support AMD, CommonJS/Node.js,
// Rhino, and plain browser loading.
if (true) {
var esprima = function (module) {
return factory();
}({});
} else if (typeof exports !== 'undefined') {
factory(exports);
} else {
factory((root.esprima = {}));
}
}(this, function (exports) {
exports = exports || {};
// Esprima source code
// ...
// Returns exports
return exports;
}));
Shimmed Library Support
- Automatically clean shimmed libraries and provide new instructions using the
onModuleBundleComplete
config property. - Added the
shimOverrides
option that allows you to pass an expression to override shimmed module return values
New Options, Gulp.js Build, More Unit Tests, Updated Docs
Changelog:
- Integrated Gulp.js for the project build system.
- Automatically removed require method calls with empty callback function expressions
- Updated the contributing guide
- Added a new
removeAllRequires
option that will remove all require method calls from the code - Added a new
ignoreModules
option that will ignore (not remove) specified AMD defined modules - Added a new
commentCleanName
option that allows you to customize the comment text that will exclude certain modules from being cleaned - Updated Jasmine unit tests
- Updated contributing guide