Skip to content

Instantly share code, notes, and snippets.

@rikkit
Last active February 17, 2024 04:43
Show Gist options
  • Save rikkit/b636076740dfaa864ce9ee8ae389b81c to your computer and use it in GitHub Desktop.
Save rikkit/b636076740dfaa864ce9ee8ae389b81c to your computer and use it in GitHub Desktop.
Rollup + TypeScript + source maps + .d.ts files
{
...
"source": "src/index.ts",
"main": "dist/main.cjs",
"module": "dist/module.mjs",
"types": "dist/index.d.ts",
"scripts": {
"dev": "rollup -w -c",
"build": "rollup -c",
"prepack": "yarn run build",
"test": "jest"
},
"devDependencies": {
"@rollup/plugin-typescript": "^8.3.1",
"rollup": "^2.70.1",
"rollup-plugin-delete": "^2.0.0",
"rollup-plugin-dts": "^4.2.0",
"rollup-plugin-sourcemaps": "^0.6.3",
"tslib": "^2.3.1",
"typescript": "^4.6.2",
},
"packageManager": "yarn@3.2.0"
}
import typescript from "@rollup/plugin-typescript";
import sourcemaps from "rollup-plugin-sourcemaps";
import dts from "rollup-plugin-dts";
import del from "rollup-plugin-delete";
export default [
{
input: "src/index.ts",
output: [
{
sourcemap: "inline",
file: "dist/main.cjs",
format: "cjs"
},
{
sourcemap: "inline",
file: "dist/main.mjs",
format: "es"
},
],
plugins: [
typescript({ sourceMap: true, inlineSources: true, tsconfig: "./tsconfig.json" }),
sourcemaps(),
],
},
{
input: "dist/types/index.d.ts",
output: [{
file: "dist/index.d.ts",
format: "es",
plugins: []
}],
plugins: [
dts(),
del({ targets: "dist/types", hook: "buildEnd" })
],
}
];
{
"compileOnSave": false,
"compilerOptions": {
"target": "es2015",
"moduleResolution": "node",
"strict": true,
"declaration": true,
"esModuleInterop": true,
"allowSyntheticDefaultImports": true,
"sourceMap": true,
"importHelpers": true,
"skipLibCheck": true,
"resolveJsonModule": true,
"declarationDir": "./types" # NB this is inside the /dist dir as per rollup config!
},
"include": [
"src/**/*.ts",
"types/globals.d.ts",
],
"exclude": [
"**/__tests__/*",
"**/__mocks__/*"
]
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment