rollup-plugin-amd
rollup-plugin-amd copied to clipboard
[workaround] Doesn't work with later than es2020 syntax like optional chaining
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!