It's 2024. You should use tsup instead of this.
π₯ Blazing fast builds
π CommonJS bundle
π² .mjs bundle
β¨ .d.ts bundle + type-checking
π§ Source maps
- Install pnpmor replace thepnpm ipart with Yarn or NPM.
- 
Run this in your terminal: pnpm i esbuild rollup rollup-plugin-esbuild rollup-plugin-dts -D wget -O rollup.config.js https://gist.github.com/aleclarson/9900ed2a9a3119d865286b218e14d226/raw/rollup.config.js 
- 
Ensure your tsconfig.jsoncontains these values:"compilerOptions": { "target": "esnext" } 
- 
Ensure your package.jsoncontains these values (and replace themy-libpart):"main": "dist/my-lib.js", "module": "dist/my-lib.mjs", "typings": "dist/my-lib.d.ts", 
- 
Change the input: 'src/index.ts'line inrollup.config.jsif needed.
- 
All done! Now do yarn rollup -cto build, or add this to yourpackage.json:"scripts": { "build": "rollup -c" } 
+1 to @FlavioZanoni's
rollup.config.jsamendment; it also took care of:[!] RollupError: Node tried to load your configuration as an ES module even though it is likely CommonJS.mentioned by @ffind
[edit] @FlavioZanoni's config removes
sourcemap: true; you can add it back at lines 19 and 29.