rollup-plugin-amd icon indicating copy to clipboard operation
rollup-plugin-amd copied to clipboard

[workaround] Doesn't work with later than es2020 syntax like optional chaining

Open rgodha24 opened this issue 2 years ago • 0 comments

The underlying library (@buxlabs/amd-to-es6) doesn't work with things like optional chaining. I figured out a decently simple workaround and wanted to share it so you guys don't have to spend 2 hours on it!

import { transform } from "@swc/core";
// also works with rollup. vite + rollup have same api here
import type { Plugin } from "vite";

const es2019 = (): Plugin => ({
  // or name: "rollup-plugin-transform-to-es2019",
  name: "vite-plugin-transform-to-es2019",
  async transform(code, id, options) {
    return await transform(code, { jsc: { target: "es2019" } });
  },
});

add this plugin BEFORE rollup-plugin-amd and it should fix all issues with transpiling. @piuccio lmk if you want me to pr this into the library instead of just having it as a workaround!

rgodha24 avatar Aug 02 '23 19:08 rgodha24