Enabling ES7 Async/Await With JSPM

I just added JSPM compilation in my SailsJS environment so that I could start porting the app to React. Implemented using athlite’s recommendation here.

Of course, I want to be able to use async/await in my client, I’ve done this before using straight Bable, but for JSPM I had to do some extra digging. The solution? Simply modify your config.js file for JSPM to include stage: 0 and es7.decorators in the optional array:

1
2
3
4
5
6
7
8
  babelOptions: {
    "stage": 0,
    "optional": [
      "runtime",
      "optimisation.modules.system",
      "es7.decorators"
    ]
  }

You don’t even need to explicitly add the Babel regenerator like with other implementations, works out of the box! Credit to this Gitter archive.