Skip to content
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.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion packages/plugin-react/package.json
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
@@ -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