- Notify ts
{
"compilerOptions": {
"declaration": true, // Generate .d.ts file
"declarationDir": "dist/types", // Output directory
"outDir": "dist", // Output directory
}
}
- Adjust vite.config.ts
// Library mode packaging src/main.ts
import { defineConfig } from 'vite'
import path from 'path'
import dts from 'vite-plugin-dts';
export default defineConfig({
plugins: [
dts({
outDir: 'dist/types', // Declaration file output directory
include: ['src/**/*.ts'], // Included files
}),
],
build: {
lib: {
entry: path.resolve(__dirname, 'src/main.ts'),
name: 'main',
fileName: (format) => `main.${format}.js`,
},
},
})
- Add package.json can be read when used
{
"main": "dist/main.umd.js",
"module": "dist/main.es.js",
"types": "dist/types/main.d.ts",
}