alloc / vite-dts

Blazing fast plugin that generates .d.ts modules for libraries
MIT License
89 stars 15 forks source link

how is type definition exported? #4

Closed muz3 closed 2 years ago

muz3 commented 2 years ago

Hi, in my dist/.d.ts has the following content: export from "../src/index", but when we publish npm, we only push dist folder. how are we going to get the types? I don't see *.es.js has the types neither? is there anything I am doing wrong?

my vite config:

import { defineConfig } from 'vite';
import dts from 'vite-dts';

// https://vitejs.dev/config/
export default defineConfig({
  build: {
    lib: {
      entry: 'src/index.ts',
      formats: ['es'],
    },
    rollupOptions: {
      external: ['react'],
      output: {
        // Since we publish our ./src folder, there's no point
        // in bloating sourcemaps with another copy of it.
        sourcemapExcludeSources: true,
      },
    },
    sourcemap: true,
    // Reduce bloat from legacy polyfills.
    target: 'esnext',
    // Leave minification up to applications.
    minify: false,
  },
  plugins: [dts()],
});

my index.ts

export { TestButton } from './components/TestButton';

export type { TestButtonProps } from './components/TestButton';
aleclarson commented 2 years ago

The readme answers your question in the FAQ section