The simplest way to start using ES2017+ in Lambda.
This fork of serverless-babel-plugin has been updated in a few ways now that serverless/serverless-babel-plugin is unmaintained.
-
npm install headnote/serverless-babel-plugin --saveDevoryarn add -D headnote/serverless-babel-plugin -
Add plugin to
serverless.yml
plugins:
...
- serverless-babel-plugin
...
-
Create a
.babelrcfile (example below). -
Test it with
serverless package
Thanks to babel-preset-env it is now very easy to target older versions of Node. As of writing this, the latest version of Node supported by Lambda is 6.10. Example .babelrc:
{
"presets": [
["env", {
"targets": {
"node": "6.10"
}
}]
]
}
To log the stdout output from the Babel process (basically a list of all the files it processed), simply add this to serverless.yml. stderr will always be logged.
custom:
serverlessBabel:
stdout: true
- Incorporates all bugs fixed on other forks (at the time of writing this)
- Now uses
babel-preset-envinstead of deprecatedbabel-preset-latest. This allows you to easily use targeting. - Now uses a standard
.babelrcfile in your project root instead of limited babel configuration living inserverless.yml - Less verbose and prettier output by default.
- Now preserves *nix file permissions but is no longer compatible with Windows (PRs welcome).