Get browserify require paths to behave more like requirejs

Abadaba picture Abadaba · Feb 26, 2014 · Viewed 10.8k times · Source

I'm finding that it's a pain when moving files around and constantly having to rewrite the file include paths to be relative to their new folder.

I want to avoid this in my browserify code:

var View = require('../../../../base/view');

And do something more in line with requirejs where it knows my base path is js:

var View = require('base/view');

Answer

eightyfive picture eightyfive · May 17, 2014

You should use the paths option. It is not documented in browserify but in node-browser-resolve (used under the hood):

paths - require.paths array to use if nothing is found on the normal node_modules recursive walk