Skip to content

Instantly share code, notes, and snippets.

@phated
Created January 21, 2021 17:57
Show Gist options
  • Save phated/79b85f735bdd52bbec4f4b1879c9fcc5 to your computer and use it in GitHub Desktop.
Save phated/79b85f735bdd52bbec4f4b1879c9fcc5 to your computer and use it in GitHub Desktop.
Neat little Rollup script for generating a CJS version of an ESM module.
import fs from "fs";
import { builtinModules as builtin } from "module";
const pkg = JSON.parse(fs.readFileSync("./package.json"));
export default {
input: "./src/index.js",
output: {
file: "build/index.cjs",
format: "cjs",
},
external: [
...Object.keys(pkg.dependencies),
...builtin,
]
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment