browserify / browserify/browserify

add support for multiple exposes in browserify.require()

Open
#1,051 4 comments 0 reactions 0 assignees View on GitHub
Dominant language
JavaScript
Stars
14.7k
Forks
1.2k
PR merge metrics
No merged PRs in 30d

Description

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 https://github.com/substack/node-browserify/issues/881#issuecomment-56052706 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](https://terinstock.com/blog/2014/02/27/replacing-packages-in-a-browserify-bundle.html), 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?

Contributor guide

No contributing guide indexed for this repository

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.