Skip to content

Conversation

aaronholsonege
Copy link
Contributor

New config.onJsProcessComplete option

The purpose of this new build config callback is to give access to a JS bundle content right before it would be optimized with UglifyJS or Closure (or not).

The config.onModuleBundleComplete callback is called when a module is finished being assembled, but this happens before pragma.process is called, which modifies the code even more (conditional comments, use strict removal, etc). Some libraries that depend upon this callback simply to access the code before it is optimized can run into issues when items processed in pragma.process happen after their callback. config.onJsProcessComplete is called immediately after pragmas.process and immediately before optimization.

This will also allow for easy integration for any JavaScript optimizer not officially supported by r.js, including custom or legacy versions of officially supported optimizers.

Example Usages

// AMDClean
onJsProcessComplete: function(fileContents, fileName) {
    return amdclean.clean({ code: fileContents });
}

// Custom version of UglifyJS
onJsProcessComplete: function(fileContents, fileName) {
    return CustomUglifyJS.minify(fileContents, { fromString: true });
}

to a JS build immediately before it is optimized.
@aaronholsonege aaronholsonege changed the title Add config.onJsProcessComplete Add config.onJsProcessComplete option Dec 30, 2014
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant