Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

源文件的.d.ts中的内容无法在构建后的文件中看到 #401

Open
3 tasks done
tangerball opened this issue Dec 11, 2024 · 0 comments
Open
3 tasks done

Comments

@tangerball
Copy link

Describe the bug

1、模块解析错误:
当我在 vite.config.js 中设置 rollupTypes: true 时,Vite 报错 [vite:dts] Internal Error: getResolvedModule() could not resolve module name "../types/axios.d"。
2、类型声明文件未包含在构建输出中:
当我同时设置 rollupTypes: true 和 copyDtsFiles: true 时,我发现 types/axios.d.ts 文件的内容并没有出现在构建输出目录 dist 中的 index.d.ts 文件里。
3、目录规划问题:
如果只设置 copyDtsFiles: true,虽然可以将类型声明文件复制到构建输出目录,但这并不符合我后期库的多入口文件目录规划。

Reproduction

/

Steps to reproduce

types/axios.d.ts

import 'axios'

declare module 'axios' {
    isNeedToken?: boolean
}

export * from 'axios'

src/index.ts

const test=()=>{}

export * from '../types/axios.d'

export default test

vite.config.js

import { defineConfig } from 'vite'
import { resolve } from 'path'
import dts from 'vite-plugin-dts'

export default defineConfig({
  plugins: [
    dts({
      tsconfigPath: resolve(__dirname, 'tsconfig.json'),
      rollupTypes: true,
      copyDtsFiles: true,
    }),
  ],
  build: {
    lib: {
      entry: resolve(__dirname, 'src/index.ts'),
      name: 'MyLibrary',
      formats: ['es', 'cjs', 'umd', 'iife'],
      exports: 'named',
      fileName: (format) => `index.${format}.js`,
    },
  },
})

System Info

vite 5.1.18
vite-plugin-dts 3.7.3
typescript 5.6.2

Validations

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant