Zero-config TypeScript declaration file generator for Vite library mode
npm install vite-plugin-sexy-declare-typeZero-config TypeScript declaration file generator for Vite library mode

- ✨ Zero configuration - works out of the box
- 🎯 Automatic entry detection from Vite library config
- ⚡ Fast declaration generation using TypeScript Compiler API
- Vite 7.0.0+
- TypeScript 5.0.0+
``bash`
pnpm add -D vite-plugin-sexy-declare-type
vite.config.ts
`typescript
import { defineConfig } from 'vite';
import sexyDeclareType from 'vite-plugin-sexy-declare-type';
export default defineConfig({
build: {
lib: {
entry: './src/index.ts',
formats: ['es'],
},
},
plugins: [sexyDeclareType()],
});
`
That's it! When you run vite build, declaration files (.d.ts) will be automatically generated alongside your build output.
This plugin focuses on declaration file generation, not type validation. For production builds, always run type checking first:
`json`
{
"scripts": {
"build": "tsc --noEmit && vite build"
}
}
This ensures:
- ✅ Type errors are caught before build
- ✅ Clean build output without warnings
- ✅ Production-ready type declarations
- Library Mode Only: Only works with Vite's library mode (build.lib)tsc --noEmit
- No tsconfig Inheritance: Uses hardcoded TypeScript options for maximum compatibility
- May generate declarations even with type errors in your code
- Run first for comprehensive type checking
Check if library mode is configured:
`typescript`
export default defineConfig({
build: {
lib: {
// ← Must have this
entry: './src/index.ts',
},
},
});
The plugin uses simplified TypeScript config for broad compatibility. If you need precise type validation:
1. Run type check before build:
`bash`
pnpm tsc --noEmit
2. Update to build script:
`json``
{
"scripts": {
"build": "tsc --noEmit && vite build"
}
}