Last active
May 21, 2025 10:09
-
-
Save rikkit/b636076740dfaa864ce9ee8ae389b81c to your computer and use it in GitHub Desktop.
Rollup + TypeScript + source maps + .d.ts files
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
{ | |
... | |
"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": "[email protected]" | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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" }) | |
], | |
} | |
]; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Show hidden characters
{ | |
"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