2

I am very new to Browserify so I apologize in advance if this sounds like a fundamentally stupid idea.

Context: I have been writing my web app using the modular design with one global namespace (let's say ns and modules are accessed through the namespace like such ns.moduleA. I use grunt for concatenating together all JS files and I manually manage the dependency (their order of concatenation). After I discovered Browserify I would like to migrate my code base to it.

However the project depends on many libraries, quite a few of which do not seem to work nicely with AMD or CJS (according to their github issue lists), and after researching through solutions such as browserify-shim and such, it seems to be quite a pain.

Proposed solution: I concatenate all the dependent libraries and stick it into a libs.js, so the libraries are all exposed to global namespace, so they're universally accessible. Then for my code I do not have to worry about require'ing them and just use them as is. For example, with jQuery, instead of doing var $ = require('jquery'); $('a').b();, I can simply do $('a').b(). I do realize that this is against the philosophy that Browserify manages all dependencies for you, but it seems to be much easier to manage the external libraries myself than using existing solutions.

Question: Is this a good practice? (I suspect not), and why?

Thank you.

saulgoodman
  • 124
  • 1
  • 9

1 Answers1

2

After some more researching around, I came across to this post which is helpful for my situation. Here's the link to it, maybe it will help someone else sharing the same problem. How do I use Browserify with external dependencies?

Community
  • 1
  • 1
saulgoodman
  • 124
  • 1
  • 9