Very trivial problem it seems. I have a rollup typescript config using rollup-plugin-typescript and rollup-plugin-dts. I want to bundle all my d.ts files into one d.ts file instead of having it mirroring my project structure. I followed some tutorials and ended up with the configs below.
The problem: dts() bundles the file correctly but leaves the original build structure as is. None of my resources addresses this. Shouldn't the now obsolete input files be deleted? Am I handling the plugin badly?
Where I start:
dist/
├── index.js
├─ dts //I compile my types into here, below is my mirrored project structure
├── components
│ ├── Button.d.ts
│ ├── index.d.ts
├── index.d.ts
What I want:
dist/
├── index.js
├── index.d.ts //everything bundled here
Unfortunately what I get:
dist/
├── index.js
├─ dts //All of this is still here, it shouldn't be
├── components
│ ├── Button.d.ts
│ ├── index.d.ts
├── index.d.ts
├── index.d.ts //It bundled correctly to this additional file though
tsconfig.json
{
"compilerOptions": {
"allowJs": true,
"allowSyntheticDefaultImports": true,
"declaration": true,
"declarationDir": "dts",
"downlevelIteration": true,
"esModuleInterop": true,
"forceConsistentCasingInFileNames": true,
"isolatedModules": true,
"jsx": "react-jsx",
"lib": ["dom", "dom.iterable", "esnext"],
"module": "esnext",
"moduleResolution": "node",
"noEmit": true,
"noFallthroughCasesInSwitch": true,
"noImplicitAny": true,
"resolveJsonModule": true,
"skipLibCheck": true,
"sourceMap": true,
"strict": true,
"target": "es5",
"strictFunctionTypes": true
},
"include": ["src/"],
"exclude": ["node_modules", "build", "dist", "src/stories/**", "**/*.stories.ts", "**/*.test.ts", "**/*.test.tsx"]
}
rollup.config.js
import babel from 'rollup-plugin-babel';
import resolve from '@rollup/plugin-node-resolve';
import external from 'rollup-plugin-peer-deps-external';
import { terser } from 'rollup-plugin-terser';
import commonjs from '@rollup/plugin-commonjs';
import dts from 'rollup-plugin-dts';
import typescript from '@rollup/plugin-typescript';
export default [
{
input: './src/index.ts',
output: [
{
file: 'dist/index.js',
format: 'cjs',
},
{
file: 'dist/index.es.js',
format: 'es',
exports: 'named',
},
],
plugins: [
typescript({
tsconfig: './tsconfig.json',
}),
babel({
exclude: 'node_modules/**',
presets: ['@babel/preset-react'],
}),
resolve(),
commonjs(),
external(),
terser(),
],
},
{
input: './dist/dts/index.d.ts',
output: [{ file: 'dist/index.d.ts', format: 'es' }],
plugins: [dts()],
},
];