thlorenz / browserify-shim

📩 Makes CommonJS incompatible files browserifyable.
MIT License
933 stars 87 forks source link

Can't handle multiple depends from the same file. #129

Closed Neppord closed 9 years ago

Neppord commented 9 years ago
{
  "browserify-shim": {
    "bootstrap": {"depends": ["jquery:jQuery", "jquery:$"]}
  }
}

Seams to break.

Neppord commented 9 years ago

There is a workaround for those interested.

By adding 2 aliases:

{
  "browser": {
    "$": "path/to/jquery",
    "jquery": "path/to/jquery"
  },
  "browserify-shim": {
    "bootstrap": {"depends": ["jquery:jQuery", "$:$"]}
  }
}
bendrucker commented 9 years ago

Why would you need to do that?

Neppord commented 9 years ago

Hi @bendrucker!

If you one of your libraries, bootstrap in this example, checks for one and uses the other.

So it checks for the jQuery var to see if it exists but then uses $ for all its manipulations. check: https://github.com/twbs/bootstrap/blob/master/dist/js/bootstrap.js#L7 usage: https://github.com/twbs/bootstrap/blob/master/dist/js/bootstrap.js#L13

update:

i see here that bootstrap is a better citizen and actual only uses jQuery, the $ is from the function scope assigned to the argument.

but there are definitely others that is less well behaved.

bendrucker commented 9 years ago

The syntax on this would be very tricky. Doesn't seem like an especially prominent issue, especially since it's really only going to affect jQuery plugins. If you're up for it, adding the workaround to the wiki seems like the best bet here.