Browserify api: how to pass advanced option to script
I am writing a small script using the Browserify API and following the readme here.
All works ok except when I need to pass a flag listed under the advanced options, for which there seems to be no coverage in the API. What I would like to pass is the --node
flag.
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'));
}
In the command line this would translate into watchify src/index.js --node -o bundle.js
(and it works).
I think that the line in the docs that says:
All other options are forwarded along to module-deps and browser-pack directly.
may contain some help but it's not clear to me how. Any pointers on this?
Answer
After looking at the source code of Browserify I came up with the answer to my own question.
I ran the watchify src/index.js --node -o bundle.js
command and logged the options passed to the Browserify.prototype._createPipeline
function.
In my case the code would become:
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
});
I ended up removing some of these options from my script because most are just default values, but I'll leave them in the answer for future reference, hopefully somebody else will benefit from it anyway.
Related Questions
- → How to update data attribute on Ajax complete
- → October CMS - Radio Button Ajax Click Twice in a Row Causes Content to disappear
- → Octobercms Component Unique id (Twig & Javascript)
- → Passing a JS var from AJAX response to Twig
- → Laravel {!! Form::open() !!} doesn't work within AngularJS
- → DropzoneJS & Laravel - Output form validation errors
- → Import statement and Babel
- → Uncaught TypeError: Cannot read property '__SECRET_DOM_DO_NOT_USE_OR_YOU_WILL_BE_FIRED' of undefined
- → React-router: Passing props to children
- → ListView.DataSource looping data for React Native
- → Can't test submit handler in React component
- → React + Flux - How to avoid global variable
- → Webpack, React & Babel, not rendering DOM