Create a gist now

Instantly share code, notes, and snippets.

Babel Post-Install Hook Idea
#!/usr/bin/env node
try {
require('./')
} catch (err) {
var name = require('path').dirname(__dirname)
console.log('es6 not supported in your environment, downgrading '+name+' to es5')
var lazyRequire = require('lazy-require')
lazyRequire('babel', function(err){
if ( err ) {
process.stderr.write(err.stack.toString()+'\n')
process.exit(-1)
return
}
require('child_process').exec('./node_modules/.bin/babel lib --out-dir es5; rm -Rf lib; mv es5 lib', {stdio:'inherit'}, function(err){
if ( err ) {
process.stderr.write(err.stack.toString()+'\n')
process.exit(-1)
return
}
console.log(name+' was sucessfully downgraded from es6 to es5')
})
})
}
{
"dependencies": {
"lazy-require": "^2.0.0"
},
"scripts": {
"postinstall": "./es6guardian.js"
}
}
@lukehorvat

Nice idea. :)

@balupton
Owner

I've abandoned the above postcompile idea for a precompile then fallback idea.

See https://github.com/bevry/esnextguardian and https://github.com/bevry/base for the latest way I do this.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment