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 });
我最终从我的脚本中删除了一些这些选项,因为大多数只是默认值,但是我将把它们留在答案中供将来参考,希望别人也能从中受益。
- 如何诊断这个错误?
- Browserify不会将module.exports转换为窗口属性?
- 如何使用browserify使用非commonjs库?
- 如何在运行package.json脚本时获得debugging/详细信息?
- 从gulp中使用browserify时如何暴露“要求”浏览器?
- 当使用browserify将一个socket.io依赖项与–node标志绑定在一起时,“Error:Can not find module”
- 是否有可能通过浏览器创build到redis服务器的连接?
- 使用Browserify和jQuery插件
- 我试着用'temp'和'fs'模块来使用browserify,我得到的只是这个糟糕的错误