为什么需要 browserify `paths` 定义?

Why the need for browserify `paths` definition?

link https://github.com/jhades/angularjs-gulp-example/blob/master/gulpfile.js 具有使用 browserify paths 的 gulp build-js 任务定义。我不明白它的必要性...是否可以仅将条目指定为 entries: './js/**/*.js', 并且这会导致它也搜索所有子目录...而不是明确指定paths: ['./js/controllers', './js/services', './js/directives'],哪些是同一个父目录的所有子目录?

感谢任何提示。

作者正在使用 paths 配置启用 non-relative require 调用,如 these:

require('todoCtrl');
require('todoStorage');
require('todoFocus');
require('todoEscape');
require('footer');

Browserify 模拟 Node 的模块解析机制(在 here 中有解释),当 Node 解析 non-relative require 时,它会在 node_modules 中查找。 paths 选项为 Browserify 提供了一个不在 node_modules 中的路径列表,当尝试解析 non-relative require 调用。

如果您对自己项目中模块的所有 require 调用都使用相对路径(例如 require('./js/controllers/todoCtrl')),则不需要 paths 配置选项。

嗯,一个简单的答案似乎是 **/* 没有被 browserify 识别!你必须 require("glob") 才能做到这一点......但使用 paths 指定额外的文件夹可能更简单。