Giter Site home page Giter Site logo

Comments (16)

ckvv avatar ckvv commented on June 20, 2024 1

这个和在我的机器上(mac)的打包结果不同,看结果似乎是因为在Windows上的preserveModulesRoot 参数没有生效,周末我在window机器上面测试一下,

from vite-plugin-dts.

agileago avatar agileago commented on June 20, 2024 1

插件生成出来的类型文件始终带着src目录,这是问题所在

from vite-plugin-dts.

ckvv avatar ckvv commented on June 20, 2024 1

@binvb
你可以参考这个
https://github.com/ckpack/v-ui/blob/c21a8819694f129e7dd4adb40ea581c687940d39/scripts/vite.es.js#L14-L23

from vite-plugin-dts.

qmhc avatar qmhc commented on June 20, 2024

默认的输出路径和 vite 打包输出路径一样,你可以通过插件选项 outputDir 修改输入路径。

from vite-plugin-dts.

ckvv avatar ckvv commented on June 20, 2024

@qmhc 似乎是应为插件不支持应为这个参数导致的preserveModulesRoot,参考https://rollupjs.org/guide/en/#outputpreservemodulesroot

from vite-plugin-dts.

qmhc avatar qmhc commented on June 20, 2024

使用的是插件的初始化选项,你可以查阅文档的选项部分,或者查阅 example 文件夹下的示例

from vite-plugin-dts.

ckvv avatar ckvv commented on June 20, 2024

看代码中并没有对preserveModulesRoot 做特殊处理

await runParallel(os.cpus().length, outputFiles, async outputFile => {
let filePath = outputFile.path
let content = outputFile.content
const isMapFile = filePath.endsWith('.map')
if (
!includedFileSet.has(isMapFile ? filePath.slice(0, -4) : filePath) ||
(clearPureImport && content === noneExport)
) {
return
}
if (!isMapFile && content && content !== noneExport) {
content = clearPureImport ? removePureImport(content) : content
content = transformAliasImport(filePath, content, aliases)
content = staticImport ? transformDynamicImport(content) : content
}
filePath = resolve(
outputDir,
relative(root, cleanVueFileName ? filePath.replace('.vue.d.ts', '.d.ts') : filePath)

我用下面这种方式修改了路径

  plugins: [dtsPlugin({
    cleanVueFileName: true,
    beforeWriteFile(filePath, content){
      return {
        filePath: filePath.replace(`${rootPath}/es/src`, `${rootPath}/es`),
        content,
      };
    }
  }), vue()]

from vite-plugin-dts.

qmhc avatar qmhc commented on June 20, 2024

呃,我主要是没有理解你的需求是什么。

你是希望打包出的目录接口如你开始发的这张图一样,
(这里有好多同名的 index.d.ts 被相互覆盖了)

image

还是希望是下面这种结构?
(这是注释掉 beforeWriteFile 后打包出来的结构)

31(2I(N86GW ZB~N2DBQFQ4

或者是其他的结构?

你能否详细的描述一下你的需求,是希望打包出怎么样的目录结构,与现在的差异在什么地方?

from vite-plugin-dts.

ckvv avatar ckvv commented on June 20, 2024

我是想打包的定义文件和生成的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.

ckvv avatar ckvv commented on June 20, 2024

目录不一致的原因是因为没有处理vite配置文件

//vite.config.js
{
...
build: {
  rollupOptions: {
      output: {
        entryFileNames: '[name].js',
        preserveModules: true,
        preserveModulesRoot,
      },
  }
}
...
}

其中preserveModulesRoot会修改打包的路径

from vite-plugin-dts.

qmhc avatar qmhc commented on June 20, 2024

我注释掉你项目中 scripts/vite.es.js 中的 beforeWriteFile,执行 pnpm run build:es 打包出来的结果是你说的想要的结果:

image

image

我使用的是 windows 系统下 vscode,你的 beforeWriteFile 在 windows 系统下并没有生效(由于路径中 '/''\' 的区别),注释掉之后打包出来的结果是一样的。

反而我通过 path.resolve() 处理路径后,使你的 beforeWriteFile 生效,打包后出来的结果是你说的不想要的结果:

image

image

你是在怎么的环境下发生这样的问题,我这边确实是无法复现。

from vite-plugin-dts.

ckvv avatar ckvv commented on June 20, 2024

这个也不正确,es目录下统一多了一个下src目录

这个是我现在生成的的正确的目录
https://cdn.jsdelivr.net/npm/@ckpack/v-ui/es/

from vite-plugin-dts.

qmhc avatar qmhc commented on June 20, 2024

不使用插件直接打包出来的结构如下:

image

image

es 下也是含有 src 目录的,是否有一些外部的参数或环境影响,或者有一些额外的步骤?

from vite-plugin-dts.

ckvv avatar ckvv commented on June 20, 2024

这个似乎是vite的问题,我在那边提了个issue
vitejs/vite#6509

from vite-plugin-dts.

binvb avatar binvb commented on June 20, 2024

@qmhc 可以指定生成路径吗? 我也遇到这个问题,我是调用 vite 的build方法进行打包的,而dts总是自动生成跟开发环境一样的目录,e.g.

// 生产环境
-- packages
   --- AComponent
   --- BComponent
-- src
   -- app.vue
// 打包目录
-- dist
   -- AComponent
   -- BCompoenent
// dst output
-- dist
   --packages
  --src
...

from vite-plugin-dts.

qmhc avatar qmhc commented on June 20, 2024

相关问题仍在等待 vite 分流,插件层面存在暂时解决方案,我先修改标题并关闭这个 issue 以免产生误导。

@agileago 如果你的问题仍未解决,你可以打开一个新的 issue,并提供具体的配置和环境信息,如果可以提供一个最小的复现项目,将更有助于更快地定位问题。

from vite-plugin-dts.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo 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.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.