vite-plugin-sexy-declare-type
v1.0.3
Published
Zero-config TypeScript declaration file generator for Vite library mode
Downloads
123
Maintainers
Readme
Vite Plugin Sexy Declare Type
Zero-config TypeScript declaration file generator for Vite library mode
Features
- ✨ Zero configuration - works out of the box
- 🎯 Automatic entry detection from Vite library config
- ⚡ Fast declaration generation using TypeScript Compiler API
Getting Started
Requires
- Vite 7.0.0+
- TypeScript 5.0.0+
Install
pnpm add -D vite-plugin-sexy-declare-typeQuick Start
Add plugin to Vite config
vite.config.ts
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.
Type Checking
This plugin focuses on declaration file generation, not type validation. For production builds, always run type checking first:
{
"scripts": {
"build": "tsc --noEmit && vite build"
}
}This ensures:
- ✅ Type errors are caught before build
- ✅ Clean build output without warnings
- ✅ Production-ready type declarations
Limitations
- Library Mode Only: Only works with Vite's library mode (
build.lib) - No tsconfig Inheritance: Uses hardcoded TypeScript options for maximum compatibility
- May generate declarations even with type errors in your code
- Run
tsc --noEmitfirst for comprehensive type checking
Troubleshooting
Declarations not generated
Check if library mode is configured:
export default defineConfig({
build: {
lib: {
// ← Must have this
entry: './src/index.ts',
},
},
});Types seem incorrect
The plugin uses simplified TypeScript config for broad compatibility. If you need precise type validation:
Run type check before build:
pnpm tsc --noEmitUpdate to build script:
{ "scripts": { "build": "tsc --noEmit && vite build" } }
