ForbesLindesay / browserify-middleware

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

Module with relative sub-requires #35

Closed jsilland closed 10 years ago

jsilland commented 10 years ago

Hi,

I'm trying to browserify the following library, which I have seen work well in Node and on the client-side before: https://github.com/evilstreak/markdown — I essentially define the following mapping in my express app:

app.get('/public/markdown/markdown.js', browserify(['markdown']))

Now, when I trying to load another browserified file which depends upon the markdown module, the browser logs an error in the console pointing to line 2 of index.js — the error message simply indicates the ./markdown module cannot be found.

ForbesLindesay commented 10 years ago

That's because you should be doing exports.markdown = require("markdown"); since "markdown" is an npm module. You begin the path ./ if you are requiring a local dependency, and you just put the plain name for npm dependencies.

Remember the bundling happens on the server, so it depends only on where the modules live server side, not client side.

Also, keep in mind that you only need to have the separate scripts if you are running into performance issues when serving them up as a single bundle. If this is the case, be sure to remember to add "markdown" to the list of excludes when serving up your application code. You may also want to disable caching until #34 is resolved.

P.S. in my experience, http://npmjs.org/package/marked is a much better markdown renderer.