How to create a bundler-free OpenJS Architect serverless app with Babel

Author serverless AWS Lambda functions with next-generation JS, and without using bundlers

xnoɹǝʃ uɐıɹq
Beginners’ Guide
3 min readOct 31, 2019

--

In this article we’ll set up an OpenJS Architect project that uses Babel to compile code for AWS Lambda, but without adding a bundler or additional external dependencies. Folks looking for the most minimal serverless setup for a modern JS build step, this is article for you!

Other articles in this series you may be interested in:

Let’s get started! First:

The Architect init script generates a new, single Lambda function project. Jump into the generated app and rename the source code folder. We’ll compile lib to src in a future step.

Now let’s do some things you can’t (yet) do: ES Modules in Node, and optional chaining! Modify src/lib/get-index/index.js like so:

View source

Install Babel

From the root of this app, let’s install the minimal dependencies required:

Configure Babel

Next, from the root create babel.config.js

View source

Configure npm scripts

Add the classic npm start and npm run build commands, and set up npm run build to compile lib to src.

View source

Set up CI/CD

Now that everything is working locally we can set up Begin to deploy our code from GitHub whenever we commit. Login to Begin with your GitHub account, click New app, and scroll to the big Import app button. (My first build was completed in 12.541 seconds!)

You can use the GitHub repo brianleroux/arc-example-babel-basic to get started.

That’s it!

Now you’re up and running with Babel on serverless without any extra dependencies. Here’s an ES module utilizing optional chaining in current Node + Lambda:

You can find the full source code for this tutorial here.

Special thank you to @jveres in the Architect community Slack for cooking up this direction! 🚀

Next steps

--

--