Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add config.onJsProcessComplete option #764

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open

Add config.onJsProcessComplete option #764

wants to merge 1 commit into from

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