'Passing "global" and "ignore" options to browserify via the command line
I'm using browserify with babelify to transpile a JS file. The JS file require()s a component in node_modules, which I also want transpiled.
As per the FAQ on babelify's GitHub, to achieve this I should be using the global and ignore options to specify which folder in node_modules should also be transpiled:
browserify().transform("babelify", {
global: true,
ignore: /\/node_modules\/(?!app\/)/
});
I'm using browserify via the command line and I can't figure out how to pass those options in. I'm also getting confused at whether these are options specific to browserify or babelify.
Here's the command I'm running:
browserify -t [ babelify ] input.js > output.js
Here's my .babelrc
{
"presets": [
[ "@babel/preset-env",
{
"targets": "defaults, ie >= 11"
}
]
],
"plugins": [ "@babel/plugin-proposal-object-rest-spread" ]
}
I can't find global documented anywhere in browserify's options even though the babelify README mentions it. I tried --global-transform and gave it the module name I want transpiled (fluent), but got Unexpected object exported by the fluent package. Expected a transform function.
Solution 1:[1]
It seems that normal regexes are not possible on the command line.
But you can get creative and use the inverse only:
browserify -t [ babelify --global --only [ your-main-js-directory node_modules\/app ] --presets [ @babel/preset-env ] ] input.js > output.js
You can specify more packages like this:
--only [ your-main-js-directory node_modules\/app node_modules\/another-app ]
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|---|
| Solution 1 | David Vielhuber |
