morphism-org / morphism

MIT License
0 stars 0 forks source link

Generate ESM bundles #16

Open todd-elvers opened 3 years ago

todd-elvers commented 3 years ago

We should:

This will the library more tree-shakeable and more compatible with esbuild-based bundlers like Vite and Snowpack.

todd-elvers commented 3 years ago

Here's an example of a pretty common rollup.config.ts configuration for TypeScript libraries:

import peerDepsExternal from "rollup-plugin-peer-deps-external";
import resolve from "@rollup/plugin-node-resolve";
import commonjs from "@rollup/plugin-commonjs";
import typescript from "rollup-plugin-typescript2";
import json from "@rollup/plugin-json";

const pkg = require("./package.json");

export default {
  input: "src/index.tsx",
  output: [
    {
      file: pkg.main,
      format: "cjs",
      sourcemap: true,
    },
    {
      file: pkg.module,
      format: "esm",
      sourcemap: true,
    },
  ],
  plugins: [
    peerDepsExternal(),
    resolve(),
    commonjs(),
    typescript({ useTsconfigDeclarationDir: true }),
    json({
      compact: true,
    }),
  ],
};