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

chore: clean jsxDev setup in config #128

Merged
merged 1 commit into from Mar 30, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
2 changes: 1 addition & 1 deletion packages/plugin-react/package.json
Expand Up @@ -46,6 +46,6 @@
"react-refresh": "^0.14.0"
},
"peerDependencies": {
"vite": "^4.1.0-beta.0"
"vite": "^4.2.0"
}
}
20 changes: 2 additions & 18 deletions packages/plugin-react/src/index.ts
@@ -1,7 +1,6 @@
import path from 'node:path'
import type { ParserOptions, TransformOptions } from '@babel/core'
import * as babel from '@babel/core'
import { createFilter, loadEnv, normalizePath, resolveEnvPrefix } from 'vite'
import { createFilter } from 'vite'
import type { Plugin, PluginOption, ResolvedConfig } from 'vite'
import MagicString from 'magic-string'
import type { SourceMap } from 'magic-string'
Expand Down Expand Up @@ -119,21 +118,7 @@ export default function viteReact(opts: Options = {}): PluginOption[] {
const viteBabel: Plugin = {
name: 'vite:react-babel',
enforce: 'pre',
config(userConfig, { mode }) {
// Copied from https://github.com/vitejs/vite/blob/4e9bdd4fb3654a9d43917e1cb682d3d2bad25115/packages/vite/src/node/config.ts#L477-L494

const resolvedRoot = normalizePath(
userConfig.root ? path.resolve(userConfig.root) : process.cwd(),
)
const envDir = userConfig.envDir
? normalizePath(path.resolve(resolvedRoot, userConfig.envDir))
: resolvedRoot
loadEnv(mode, envDir, resolveEnvPrefix(userConfig))

const isProduction =
(process.env.NODE_ENV || process.env.VITE_USER_NODE_ENV || mode) ===
'production'

config() {
if (opts.jsxRuntime === 'classic') {
return {
esbuild: {
Expand All @@ -148,7 +133,6 @@ export default function viteReact(opts: Options = {}): PluginOption[] {
} else {
return {
esbuild: {
jsxDev: !isProduction,
jsx: 'automatic',
jsxImportSource: opts.jsxImportSource,
jsxSideEffects: opts.jsxPure === false,
Expand Down