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

Support optional IIFE wrapping of individual source files in compressed output #405

Open
MichaelZalla opened this issue May 16, 2016 · 2 comments

Comments

@MichaelZalla
Copy link

I understand that this task supports UglifyJS's wrap and define features for wrapping the entire code output in a closure to prevent global leaks and collisions. I have a growing collection of non-application-specific Angular modules from which I can pull specific components (dependencies) into my individual Angular applications. I enjoy having the flexibility to bundle only those global components which I need for my app, instead of requiring an entire global module (and all of its usable components).

This works well in terms of the DRY principle, but it can lead to name collisions / overwrites in the compressed output if both codebases—global and app—use the same function name for functions with similar purposes (e.g.—to define default configuration vs. custom configuration).

// In /global-stuff/modules/global.backend/config/config.set-response-interceptors.js
angular
    .module('global.backend')
    .config(setResponseInterceptors);

function setResponseInterceptors(
    $httpProvider)
{
    // Global configuration
}
// In /my-cool-app/modules/app.backend/config/config.set-response-interceptors.js
angular
    .module('app.backend')
    .config(setResponseInterceptors);

function setResponseInterceptors(
    $httpProvider)
{
    // Application-specific configuration
}

Can this task support the optional wrapping of individual src files in IIFEs before the final output is written to dest? (My alternative would be to manually wrap all of my existing components, as well as all future components, in closures).

@MichaelZalla
Copy link
Author

Another alternative that I've tried:

  1. Run grunt-wrap to create a new set of wrapped source files (written to a temporary project directory).
  2. Map the original set of source paths to be relative to the temporary directory, and pass this to uglify.
  3. Clean up the temporary directory contents after the build.

This meets my needs, but it's work that could be avoided if the uglify task can support it as a feature.

@XhmikosR
Copy link
Member

Or grunt-iife.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants