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 support for multiple exposes in browserify.require() #1051

Open
faiq opened this issue Jan 6, 2015 · 4 comments
Open

add support for multiple exposes in browserify.require() #1051

faiq opened this issue Jan 6, 2015 · 4 comments

Comments

@faiq
Copy link
Contributor

faiq commented Jan 6, 2015

We've recently bumped into this issue when upgrading from version 4 to versions 5 and beyond. In our project, we're using backbone, which has a dependency on underscore, but in our other files we're using lodash as a dependency.

Since we don't want to ship both to the client, we decided to do an alias for lodash to underscore. However, this browserify -r lodash:underscore is now breaking on new versions of browserify.

I've tried multiple solutions for this:

  1. I tried the solution posted in Can't defined exposed name with require option #881 (comment) by using

    browserify -r ./node_modules/lodash:underscore

    this does work to a certain extent, but I cannot use require ('lodash') because browserify never exposes the package.

  2. Another solution was proposed by @terinjokes in his blog post, but this requires me to add additional details to my package.json. I don't think that this is the proper solution.

My proposition is to have the .require() method in browserify support an array for multiple expose names. This way, require('lodash') and require('underscore') will both resolve to underscore.

I was wondering if you are open to a pull request that implements this?

@mattdesl
Copy link
Contributor

mattdesl commented Jan 6, 2015

Sounds like something that should be implemented in a transform or plugin, nay ?

@faiq
Copy link
Contributor Author

faiq commented Jan 6, 2015

there are plugins for this, but that doesn't change the fact that this was supported in 4.2.x. and is no longer supported now. transforms make the build very very slow, as well so id like browserify to expose multiple things.

aliasing requires is still broken though you cannot do something like browserify -r underscore:lodash because it will break. I think i'll write a failing test case for that.

@faiq
Copy link
Contributor Author

faiq commented Jan 6, 2015

#1052 adds a failing test demonstrating the problem i documented above. This is also documented in #881 and #850

@JAForbes
Copy link

This one really threw me yesterday. It is surprising behaviour that this works:

bundler.require('lodash',{expose: 'underscore'})

While this doesn't

-r lodash:underscore

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

No branches or pull requests

3 participants