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

dev模式下,调用esbuild构建时的配置是否可以从vite.config.js同步读取或者支持参数传入? #278

Closed
6 tasks done
jiangkk opened this issue Oct 30, 2023 · 2 comments
Labels
duplicate This issue or pull request already exists

Comments

@jiangkk
Copy link

jiangkk commented Oct 30, 2023

Related plugins

Description

我们的业务有Chrome69的运行场景,在使用Vite的过程中,我们发现生产环境构建出来的代码可以在Chrome69下正常运行,但是dev环境下无法运行。我们尝试使用vite.config.js配置中的esbuild.target来指定执行编译的目标环境,但是通过阅读源码发现这个配置只能修改Vite在编译js,ts等文件才会生效,而.vue文件是通过vite-plugin-vue编译的,并且在调用esbuild的时候是写死了配置(

const { code, map } = await transformWithEsbuild(
) ,这导致于无法对该编译配置进行修改,是否可以考虑支持在调用esbuild的配置时和vite.config.js里的esbuild配置保持一致或者可以由用户手动传入?

Suggested solution

希望vite-plugin-vue 在dev环境下调用esbuild配置的时候,可以merge从vite.config.js传入的esbuild配置或者由用户可以手动传入。

Alternative

目前我们的解决方案是单独再写了一个插件,在vue插件执行完成之后,再调用一次esbuild处理.vue文件,使得可以编译到较低的JavaScript版本,但这样会导致一个文件需要重复编译两次,有一定性能损耗。因此仍希望官方可以支持esbuild配置传入,使得开发者可以自己选择是否需要编译到较低的语法版本,当然这可能会增加编译时间,但可以把这个决定权交给开发者。

Additional context

No response

Validations

@aweikalee
Copy link

实际上问题出在:

if (canInlineMain(descriptor, options)) {

.vue 文件中 script.langjs/ts(包含为空) 时,会将 script 中的代码作为 .vue 的内联代码。这使得这部分代码不会被其他处理 js/ts 的插件处理。

script.langjsx/tsx 时,则会以 import _sfc_main from “xxx.vue?lang.js” (tsx 时为 lang.tsx)形式插入到 .vue 文件中。虚拟模块 xxx.vue?lang.js 将返回 script 中的代码。由于虚拟模块的后缀名是 .js,会被当做 .js 文件被其他插件处理。

应该废弃内联代码,使其保持一致性:PR #222

@sapphi-red
Copy link
Member

Duplicate of #31

@sapphi-red sapphi-red marked this as a duplicate of #31 Feb 27, 2024
@sapphi-red sapphi-red closed this as not planned Won't fix, can't repro, duplicate, stale Feb 27, 2024
@sapphi-red sapphi-red added duplicate This issue or pull request already exists and removed enhancement: pending triage labels Feb 27, 2024
@github-actions github-actions bot locked and limited conversation to collaborators Mar 13, 2024
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
duplicate This issue or pull request already exists
Projects
None yet
Development

No branches or pull requests

3 participants