The best Rollup config for TypeScript libraries
source link: https://gist.github.com/aleclarson/9900ed2a9a3119d865286b218e14d226
Go to the source link to view the article. You can view the picture content, updated content and better typesetting reading experience. If the link is broken, please click the button below to view the snapshot at that time.
Features
Blazing fast builds
CommonJS bundle.mjs
bundle.d.ts
bundle + type-checking
Source maps
Install
- Install
pnpm
or replace thepnpm i
part 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.githubusercontent.com/aleclarson/9900ed2a9a3119d865286b218e14d226/raw/rollup.config.js
-
Ensure your
tsconfig.json
contains these values:"compilerOptions": { "target": "esnext" }
-
Ensure your
package.json
contains these values (and replace themy-lib
part):"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.js
if needed. -
All done! Now do
yarn rollup -c
to build, or add this to yourpackage.json
:"scripts": { "build": "rollup -c" }
Recommend
About Joyk
Aggregate valuable and interesting links.
Joyk means Joy of geeK