获取browserify需要路径的行为更像requirejs [英] Get browserify require paths to behave more like requirejs
问题描述
我发现移动文件并不断重写文件包含相对于新文件夹的路径时会很痛苦。
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.
我想要在我的browserify代码中避免这种情况:
I want to avoid this in my browserify code:
var View = require('../../../../base/view');
并根据requirejs做更多事情,知道我的基本路径是 js
:
And do something more in line with requirejs where it knows my base path is js
:
var View = require('base/view');
推荐答案
您应该使用路径
选项。它没有记录在browserify中,而是在 node-browser-resolve 中使用(在引擎盖下使用) :
You should use the paths
option. It is not documented in browserify but in node-browser-resolve (used under the hood):
paths - 如果在正常的
node_modules递归步行中找不到任何内容,则使用require.paths数组
paths - require.paths array to use if nothing is found on the normal node_modules recursive walk
这篇关于获取browserify需要路径的行为更像requirejs的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!