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

Using browser javascript libraries with browserify #59

Closed
tommedema opened this issue Aug 25, 2011 · 4 comments
Closed

Using browser javascript libraries with browserify #59

tommedema opened this issue Aug 25, 2011 · 4 comments

Comments

@tommedema
Copy link

I'm using quite a lot of complex javascript libraries on the client side.

An example: https://github.com/scottschiller/SoundManager2/blob/master/script/soundmanager2.js

Is it possible to make these libraries require-able?

@ghost
Copy link

ghost commented Aug 25, 2011

Instead of attaching your exports to the window object, attach them to module.exports or exports, just like in node. Then from another file you can just var SoundManager = require('./soundmanager2.js').

@ghost ghost closed this as completed Aug 25, 2011
@tommedema
Copy link
Author

@substack, something like this at the bottom of the example?

module.exports = window.SoundManager; ?

@7fe
Copy link

7fe commented Aug 26, 2011

@tommedema

Use the following

if (typeof module !== 'undefined' && module.exports) {
    module.exports = SoundManager;
  } else {
    window.SoundManager = SoundManager;
}

@ghost
Copy link

ghost commented Aug 26, 2011

@tommedema Sure that will work but you also don't need to assign anything to window at all, you can just have module.exports = SoundManager for a plain-old function SoundManager. That way you don't need to worry about a global SoundManager making things confusing.

This issue was closed.
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

2 participants