Browserify api:如何将高级选项传递给脚本

我正在使用Browserify API编写一个小脚本,并按照此处的自述文件。

除了当我需要通过高级选项下列出的标志时,所有的工作都可以正常工作,对于这些标志在API中似乎没有覆盖。 我想通过的是--node标志。

 var b = browserify({ entries: ['src/index.js'], cache: {}, ignoreWatch: ['**/node_modules/**', './dist/'], packageCache: {}, plugin: [watchify, babelify], debug: true, node: true // => this options does not actually exist, so it does nothing }); b.on('update', bundle); function bundle() { b.bundle() .pipe(fs.createWriteStream('bundle.js')); } 

在命令行中,这将转化为watchify src/index.js --node -o bundle.js (和它的工作原理)。

我认为文档中的一行说:

所有其他选项直接转发到模块代码和浏览器包。

可能包含一些帮助,但我不清楚如何。 任何指针呢?

看了Browserify的源代码后,我想出了自己的问题的答案。

我只需运行watchify src/index.js --node -o bundle.js命令并logging传递给Browserify.prototype._createPipeline函数的选项。

在我的情况下,代码将变成:

 var b = browserify({ entries: ['src/index.js'], cache: {}, ignoreWatch: ['**/node_modules/**', './dist/'], packageCache: {}, plugin: [watchify, babelify], debug: true, fullPaths: false, builtins: false, commondir: false, bundleExternal: true, basedir: undefined, browserField: false, detectGlobals: true, insertGlobals: false, insertGlobalVars: { process: undefined, global: undefined, 'Buffer.isBuffer': undefined, Buffer: undefined }, ignoreMissing: false, standalone: undefined }); 

我最终从我的脚本中删除了一些这些选项,因为大多数只是默认值,但是我将把它们留在答案中供将来参考,希望别人也能从中受益。