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-babilifor 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_ENVand decide whether you want to include theminifypreset.An alternative would be to use Babel's
envoption (not to confuse withbabel-preset-env), which uses the configuration that matches the value ofBABEL_ENVorNODE_ENVif noBABEL_ENVwas defined. This approach is shown inbabel-preset-minify- Usage.The
envoption is not really recommended and mainly exists because.babelrcis JSON and there is no good way to define conditional configurations. This will change in Babel 7 which allows a.babelrc.jsconfig where you have the full power of Node.js and that means you could do the same thing as with Gulp.