Skip to content

react支持.js后缀文件 #1552

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

Closed
linklin7 opened this issue Jan 15, 2021 · 8 comments
Closed

react支持.js后缀文件 #1552

linklin7 opened this issue Jan 15, 2021 · 8 comments

Comments

@linklin7
Copy link

react目前默认支持.tsx、.jsx后缀文件解释,不支持.js后缀文件解析。

image

@underfin
Copy link
Member

You can custom it by include and exclude fileds of esbuild option. See https://vitejs.dev/config/#esbuild

@ppjjzz
Copy link

ppjjzz commented Feb 1, 2021

You can custom it by include and exclude fileds of esbuild option. See https://vitejs.dev/config/#esbuild
export default {
plugins: [reactRefresh()],
esbuild: {
include: 'js'
}
}
设置了还是报错啊@underfin

@yyx990803
Copy link
Member

Include js 了也只会被 esbuild 当作 js 处理。

JSX 就用 .jsx 后缀,因为 JSX 本来就不是纯 JS。 Vite 默认对纯 JS 是不做任何处理的,把所有的 js 都当 jsx 会导致不必要的性能损失。

@ppjjzz
Copy link

ppjjzz commented Feb 1, 2021

Include js 了也只会被 esbuild 当作 js 处理。

JSX 就用 .jsx 后缀,因为 JSX 本来就不是纯 JS。 Vite 默认对纯 JS 是不做任何处理的,把所有的 js 都当 jsx 会导致不必要的性能损失。

那能否提供个选项让我配置是否对所有js文件当jsx处理?不然旧项目都是js文件没法接入

@yyx990803
Copy link
Member

批量改个后缀有这么难?

@zhangchao828
Copy link

既然都使用react了,那必然基本上都是jsx文件,都会对它处理,开放个配置对所有js都处理,对比起来没啥性能损失吧

@0xe69e97
Copy link

批量改个后缀有这么难?

尤大 666

@github-actions
Copy link

This issue has been locked since it has been closed for more than 14 days.

If you have found a concrete bug or regression related to it, please open a new bug report with a reproduction against the latest Vite version. If you have any other comments you should join the chat at Vite Land or create a new discussion.

@github-actions github-actions bot locked and limited conversation to collaborators Jul 15, 2021
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

6 participants