Comments (16)
这个和在我的机器上(mac)的打包结果不同,看结果似乎是因为在Windows上的preserveModulesRoot
参数没有生效,周末我在window机器上面测试一下,
from vite-plugin-dts.
插件生成出来的类型文件始终带着src目录,这是问题所在
from vite-plugin-dts.
@binvb
你可以参考这个
https://github.com/ckpack/v-ui/blob/c21a8819694f129e7dd4adb40ea581c687940d39/scripts/vite.es.js#L14-L23
from vite-plugin-dts.
默认的输出路径和 vite 打包输出路径一样,你可以通过插件选项 outputDir
修改输入路径。
from vite-plugin-dts.
@qmhc 似乎是应为插件不支持应为这个参数导致的preserveModulesRoot
,参考https://rollupjs.org/guide/en/#outputpreservemodulesroot
from vite-plugin-dts.
使用的是插件的初始化选项,你可以查阅文档的选项部分,或者查阅 example 文件夹下的示例
from vite-plugin-dts.
看代码中并没有对preserveModulesRoot
做特殊处理
Lines 319 to 340 in 173dfe7
我用下面这种方式修改了路径
plugins: [dtsPlugin({
cleanVueFileName: true,
beforeWriteFile(filePath, content){
return {
filePath: filePath.replace(`${rootPath}/es/src`, `${rootPath}/es`),
content,
};
}
}), vue()]
from vite-plugin-dts.
呃,我主要是没有理解你的需求是什么。
你是希望打包出的目录接口如你开始发的这张图一样,
(这里有好多同名的 index.d.ts 被相互覆盖了)
还是希望是下面这种结构?
(这是注释掉 beforeWriteFile
后打包出来的结构)
或者是其他的结构?
你能否详细的描述一下你的需求,是希望打包出怎么样的目录结构,与现在的差异在什么地方?
from vite-plugin-dts.
我是想打包的定义文件和生成的js文件平级
比如说这里有两个原始文件
src/module.ts
src/another/module.ts
现在打包后是,其中的src
目录不是我想要的
es/module.js
es/src/module.d.ts
es/another/module.js
es/src/another/module.d.ts
我想要的结果是
es/module.js
es/module.d.ts
es/another/module.js
es/another/module.d.ts
我现在是通过beforeWriteFile
把目录/es/src
替换成了/es
解决的
from vite-plugin-dts.
目录不一致的原因是因为没有处理vite配置文件
//vite.config.js
{
...
build: {
rollupOptions: {
output: {
entryFileNames: '[name].js',
preserveModules: true,
preserveModulesRoot,
},
}
}
...
}
其中preserveModulesRoot
会修改打包的路径
from vite-plugin-dts.
我注释掉你项目中 scripts/vite.es.js
中的 beforeWriteFile
,执行 pnpm run build:es
打包出来的结果是你说的想要的结果:
我使用的是 windows 系统下 vscode,你的 beforeWriteFile
在 windows 系统下并没有生效(由于路径中 '/'
和 '\'
的区别),注释掉之后打包出来的结果是一样的。
反而我通过 path.resolve()
处理路径后,使你的 beforeWriteFile
生效,打包后出来的结果是你说的不想要的结果:
你是在怎么的环境下发生这样的问题,我这边确实是无法复现。
from vite-plugin-dts.
这个也不正确,es目录下统一多了一个下src目录
这个是我现在生成的的正确的目录
https://cdn.jsdelivr.net/npm/@ckpack/v-ui/es/
from vite-plugin-dts.
不使用插件直接打包出来的结构如下:
在 es
下也是含有 src
目录的,是否有一些外部的参数或环境影响,或者有一些额外的步骤?
from vite-plugin-dts.
这个似乎是vite的问题,我在那边提了个issue
vitejs/vite#6509
from vite-plugin-dts.
@qmhc 可以指定生成路径吗? 我也遇到这个问题,我是调用 vite 的build方法进行打包的,而dts总是自动生成跟开发环境一样的目录,e.g.
// 生产环境
-- packages
--- AComponent
--- BComponent
-- src
-- app.vue
// 打包目录
-- dist
-- AComponent
-- BCompoenent
// dst output
-- dist
--packages
--src
...
from vite-plugin-dts.
相关问题仍在等待 vite 分流,插件层面存在暂时解决方案,我先修改标题并关闭这个 issue 以免产生误导。
@agileago 如果你的问题仍未解决,你可以打开一个新的 issue,并提供具体的配置和环境信息,如果可以提供一个最小的复现项目,将更有助于更快地定位问题。
from vite-plugin-dts.
Related Issues (20)
- Errors being swallowed when `rollupTypes: true` HOT 2
- 【Regression】Library which use IterableIterator.entries() cause TS Error. HOT 2
- 升级 language-tools 到 2.0 HOT 1
- Wrong definition generations since 3.8.2 for HOT 1
- feat: Add a way to get the TypeScript program instance
- 打包一个库的时候,defineProps问题 HOT 1
- 3.8.0+ Cannot build while excluding vite-env.d.ts
- Invalid imports in generated d.ts for project with tsconfig path alias defined for any module
- 【功能请求】希望可以增加一个像rollup一样可以自定义输出目录层级的功能 HOT 2
- Cannot find name'DefineComponent'
- [docs] The parameter explanation for the afterBuild option in README.md is incorrect.
- Keep comments of the variable in d.ts HOT 3
- Trigger declaration generation in vite build watch mode when non-ts file changes
- bug: tsconfig.json's "files" option is ignored HOT 1
- build fails when using yarn 4 with pnp and rollupTypes: true HOT 1
- All typescript errors are being swallowed HOT 1
- TS-Errors when building with Vite `v5.3.1` HOT 1
- DTS not compatible with latest React Vite tsconfig structure HOT 9
- `"type": "module"` with `rollupTypes: true` results in error HOT 1
- Feature: Support ${configDir} template variable in tsconfig.json (added in typescript 5.5)
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from vite-plugin-dts.