@@ -19,7 +19,7 @@ import {
19
19
import type { ResolvedConfig } from '../config'
20
20
import type { Plugin , PluginContext } from '../plugin'
21
21
import { cleanUrl } from '../../shared/utils'
22
- import type { Logger } from '..'
22
+ import type { Environment , Logger } from '..'
23
23
import type { ViteDevServer } from '../server'
24
24
import type { ESBuildOptions } from './esbuild'
25
25
import { loadTsconfigJsonForFile } from './esbuild'
@@ -301,6 +301,34 @@ export function oxcPlugin(config: ResolvedConfig): Plugin {
301
301
jsxExclude || / \. ( m ? [ j t ] s | t s x ) $ / ,
302
302
)
303
303
304
+ const getModifiedOxcTransformOptions = (
305
+ oxcTransformOptions : OxcTransformOptions ,
306
+ id : string ,
307
+ environment : Environment ,
308
+ ) : OxcTransformOptions => {
309
+ const result : OxcTransformOptions = {
310
+ ...oxcTransformOptions ,
311
+ sourcemap :
312
+ environment . mode !== 'build' || ! ! environment . config . build . sourcemap ,
313
+ }
314
+
315
+ const jsxOptions = result . jsx
316
+ // disable refresh at ssr
317
+ if (
318
+ environment . config . consumer === 'server' &&
319
+ typeof jsxOptions === 'object' &&
320
+ jsxOptions . refresh
321
+ ) {
322
+ result . jsx = { ...jsxOptions , refresh : false }
323
+ }
324
+
325
+ if ( ( jsxFilter ( id ) || jsxFilter ( cleanUrl ( id ) ) ) && ! result . lang ) {
326
+ result . lang = 'jsx'
327
+ }
328
+
329
+ return result
330
+ }
331
+
304
332
let server : ViteDevServer
305
333
306
334
return {
@@ -310,30 +338,16 @@ export function oxcPlugin(config: ResolvedConfig): Plugin {
310
338
} ,
311
339
async transform ( code , id ) {
312
340
if ( filter ( id ) || filter ( cleanUrl ( id ) ) ) {
313
- const oxcTransformJsxOptions = oxcTransformOptions . jsx
314
- // disable refresh at ssr
315
- if (
316
- this . environment . config . consumer === 'server' &&
317
- typeof oxcTransformJsxOptions === 'object' &&
318
- oxcTransformJsxOptions . refresh
319
- ) {
320
- oxcTransformJsxOptions . refresh = false
321
- }
322
- if (
323
- ( jsxFilter ( id ) || jsxFilter ( cleanUrl ( id ) ) ) &&
324
- ! oxcTransformOptions . lang
325
- ) {
326
- oxcTransformOptions . lang = 'jsx'
327
- }
328
- oxcTransformOptions . sourcemap =
329
- this . environment . mode !== 'build' ||
330
- ! ! this . environment . config . build . sourcemap
331
-
341
+ const modifiedOxcTransformOptions = getModifiedOxcTransformOptions (
342
+ oxcTransformOptions ,
343
+ id ,
344
+ this . environment ,
345
+ )
332
346
const result = await transformWithOxc (
333
347
this ,
334
348
code ,
335
349
id ,
336
- oxcTransformOptions ,
350
+ modifiedOxcTransformOptions ,
337
351
undefined ,
338
352
config ,
339
353
server ?. watcher ,
0 commit comments