I am using babelify
and babili
for JS minification, via gulp:
// Now run the watchifys function for this bundle
watchifysForBundle[jsBundle]
// Note: we don't use any babel presets - instead we just write code in what evergreen browsers support
.transform(babelify, {
presets: ['babel-preset-babili'],
ignore: ['buffer']
})
However I can't seem to find how to pass the options to check NODE_ENV and disable babeli
when not in production. The babelify docs don't seem to help, even with this common use case.
How can I disable babelify minification when not in production?
Babili is deprecated and has been renamed to
babel-minify
, so you should be using that instead.To disable the minification in development you simply don't use the
babel-preset-minify
(orbabel-preset-babili
for that matter). As you're using Gulp you can use everything Node.js has to offer to decide which presets you want to include, which means that you can checkprocess.env.NODE_ENV
and decide whether you want to include theminify
preset.An alternative would be to use Babel's
env
option (not to confuse withbabel-preset-env
), which uses the configuration that matches the value ofBABEL_ENV
orNODE_ENV
if noBABEL_ENV
was defined. This approach is shown inbabel-preset-minify
- Usage.The
env
option is not really recommended and mainly exists because.babelrc
is JSON and there is no good way to define conditional configurations. This will change in Babel 7 which allows a.babelrc.js
config where you have the full power of Node.js and that means you could do the same thing as with Gulp.