ForbesLindesay / browserify-middleware

express middleware for browserify, done right
http://browserify.org
MIT License
381 stars 66 forks source link

Support different basedir per browserify() call #19

Closed afbobak closed 10 years ago

afbobak commented 11 years ago

I have an application structure where the express server is being instantiated in a different module from the handlers and the handlers are injected. Basically something like this:

+--app
    \
     +--http-server
     |  \
     |   +--express 
     +--handler
        \
         +--dependencies

Because the module search is relative to __dirname of the caller (which in fact is the module that creates the express-app) browserify-middleware isn't able to pull in the browser dependencies from the other branch.

A "basedir"-option on the browserify() call would solve that problem, e.g.:

app.use("/js/base.js", browserify(["dependency1", "dependency2"], {
    basedir : __dirname
  });
ForbesLindesay commented 10 years ago

I'm not convinced this is needed. Your dependencies should be in a node_modules folder at the top level scope. If they are, they should be found by the resolution algorithm.