Making AWS Amplify work with Rollup

AWS Amplify assumes CommonJS, which Rollup doesnโ€™t work well with (Hence all Amplify web app examples use Webpack). I recently discovered that you can make it work with Rollup with a few tweaks.

Letโ€™s take the default Svelte app, which uses Rollup:

npx degit sveltejs/template my-svelte-project
cd my-svelte-project
npm install

This default rollup template lacks just two things you need to use Amplify with Rollup. Install @rollup/plugin-json:

npm i -D @rollup/plugin-json

And add it to your rollup.config.js. Also set the node-resolve pluginโ€™s preferBuiltins option to false:

import resolve from "@rollup/plugin-node-resolve";
import json from "@rollup/plugin-json"; // new!

export default {
  // ...
  plugins: [
    // ...
    resolve({
      browser: true,
      preferBuiltins: false, // new!
      dedupe: ["svelte"],
    }),
    json(),                  // new!
    // ...
  ]
}

And now you are done!

This setup will work fine with Amplify. For a full demo adding a full Amplify CRUD backend to a working Svelte frontend in under 30 mins, check out my recent practice run here!

Dev.to Embed: {% youtube hCoRYc_FzK0 %}

Tagged in: #tech #aws #amplify #rollup #javascript

Leave a reaction if you liked this post! ๐Ÿงก
Loading comments...
Webmentions
โค๏ธ 0 ๐Ÿ’ฌ 2
  • avatar of shawn swyx wang
    shawn swyx wang mentioned this on 2020-06-08

    haha really? wasn't aware there were open issues. I just know from prior experience the Rollup part tripped me up before and decided to try fixing it

  • avatar of Jesper Bylund
    Jesper Bylund mentioned this on 2020-06-08

    This is really nice: AWS Amplify + Sveltejs. @swyx solved an issue that has been active in two github repos for months. swyx.io/writing/makingโ€ฆ

  • No further replies found. Tweet about this post and it will show up here!

Subscribe to the newsletter

Join >10,000 subscribers getting occasional updates on new posts and projects!

I also write an AI newsletter and a DevRel/DevTools newsletter.

Latest Posts

Search and see all content