Repository navigation
It it possible to use plugin-typescript for generating d.ts exclusively? #1573
|
I compile my TS code with sucrase and I want to also generate d.ts for my files. It works out that Is there any way to completely prevent it from touching any generated code, while still generating typings? |
Replies: 1 comment 1 reply
|
Yes. Use import typescript from '@rollup/plugin-typescript';
import sucrase from '@rollup/plugin-sucrase';
export default {
input: 'src/index.ts',
output: { dir: 'dist', format: 'es' },
plugins: [
typescript({ tsconfig: './tsconfig.json', noForceEmit: true }),
sucrase({ transforms: ['typescript'] }),
],
};{
"compilerOptions": {
"target": "ESNext",
"module": "ESNext",
"moduleResolution": "Bundler",
"strict": true,
"declaration": true,
"emitDeclarationOnly": true,
"declarationDir": "dist/types",
"rootDir": "src"
},
"include": ["src/**/*.ts"]
}The important part is I checked this with plugin-typescript That keeps TypeScript out of JavaScript emission, but it still performs type analysis for the declarations, and Rollup itself can alter final bundle formatting. The byte-for-byte comparison above is against a Sucrase-only Rollup build, not a promise that the bundle preserves the original source layout in every case. I tested a non-watch build. |
Yes. Use
noForceEmit: truetogether with TypeScript'sdeclaration: trueandemitDeclarationOnly: true, then let Sucrase handle the JavaScript transform:{ "compilerOptions": { "target": "ESNext", "module": "ESNext", "moduleResolution": "Bundler", "strict": true, "declaration": true, "emitDeclarationOnly": true, "declarationDir": "dist/types", "r…