From a09000357d1115919aafc78a3c3038c46fe6dfa5 Mon Sep 17 00:00:00 2001 From: jongleberry Date: Fri, 6 Nov 2015 09:45:53 -0800 Subject: [PATCH] add docs for babel --- docs/api/index.md | 23 +++++++++++++++++++++++ 1 file changed, 23 insertions(+) diff --git a/docs/api/index.md b/docs/api/index.md index 886b987..9135337 100644 --- a/docs/api/index.md +++ b/docs/api/index.md @@ -85,6 +85,29 @@ app.use(function *(){ app.listen(3000); ``` +## Async Functions with Babel + +To use `async` functions in Koa, we recommend using [babel's require hook](http://babeljs.io/docs/usage/require/). + +```js +require('babel-core/register'); +// require the rest of the app that needs to be transpiled after the hook +const app = require('./app'); +``` + +To parse and transpile async functions, +you should at a minimum have the [transform-async-to-generator](http://babeljs.io/docs/plugins/transform-async-to-generator/) +or [transform-async-to-module-method](http://babeljs.io/docs/plugins/transform-async-to-module-method/) plugins. +For example, in your `.babelrc` file, you should have: + +```json +{ + "plugins": ["transform-async-to-generator"] +} +``` + +Currently, you could also use the [stage-3 preset](http://babeljs.io/docs/plugins/preset-stage-3/). + ## Settings Application settings are properties on the `app` instance, currently