I am trying to compile a Koa app, and Koa has assertions that check to make sure that I am passing generator functions as middleware. However, I would like to compile my server side code from ES7 using Babel, for consistency with the front end code.
Is it possible to target node harmony, instead of ES5? I don't see anything promising in the options, but choosing a target seems like a standard thing to be able to do with a compiler.
update
Blacklisting Babel's regenerator transform seems to have no effect, even though I am using stage: 1
.
index.js:
require( "babel/register" )({
sourceMaps: "inline",
stage: 1,
blacklist: [ "regenerator" ],
optional: [ "asyncToGenerator" ]
});
var app = require( "./src/server" );
app.listen( process.env.port || 3000 );
src/server.js:
import koa from "koa";
import router from "koa-router";
router.get( "/", function *( next ) {
this.body = "Hi!";
});
let app = koa();
app.use( router() );
export default app;
Execute: node --harmony index.js
node --version
v0.12.4
There isn't really a standard definition of
--harmony
since it would depend on what version of Node or iojs you happen to be using. The best you can do with Babel is explicitly decide what transformations to run. Babel allows you to provide awhitelist
and/orblacklist
option e.g.for instance would stop transpiling ES6 classes and rely on your platform supporting them. The main list of transforms is here.
'regenerator'
in this case would disable transpiling generators. If you disable that however, and you are using async functions, you'd want to then passoptional: ['asyncToGenerator']
to enable the transformation of async functions into standard generators with a wrapper function, as they'd otherwise end up in the final output.