1
1
import path from 'path'
2
- import type { ReactCompilerOptions } from '../server/config-shared'
2
+ import type { JSONValue , ReactCompilerOptions } from '../server/config-shared'
3
3
import type { NextBabelLoaderOptions } from './babel/loader/types'
4
4
5
5
function getReactCompiler ( ) {
@@ -15,27 +15,26 @@ function getReactCompiler() {
15
15
}
16
16
17
17
const getReactCompilerPlugins = (
18
- options : boolean | ReactCompilerOptions | undefined ,
19
- isServer : boolean
20
- ) => {
21
- if ( ! options || isServer ) {
18
+ maybeOptions : boolean | ReactCompilerOptions | undefined ,
19
+ isServer : boolean ,
20
+ isDev : boolean
21
+ ) : undefined | JSONValue [ ] => {
22
+ if ( ! maybeOptions || isServer ) {
22
23
return undefined
23
24
}
24
25
25
- const compilerOptions = typeof options === 'boolean' ? { } : options
26
- if ( options ) {
27
- return [
28
- [
29
- getReactCompiler ( ) ,
30
- {
31
- // https://react.dev/reference/react-compiler/panicThreshold
32
- panicThreshold : 'none' ,
33
- ...compilerOptions ,
34
- } ,
35
- ] ,
36
- ]
26
+ const defaultOptions : ReactCompilerOptions = isDev
27
+ ? {
28
+ // TODO: enable `environment.enableNameAnonymousFunctions`Ï
29
+ }
30
+ : { }
31
+ const options : ReactCompilerOptions =
32
+ typeof maybeOptions === 'boolean' ? { } : maybeOptions
33
+ const compilerOptions : JSONValue = {
34
+ ...defaultOptions ,
35
+ ...options ,
37
36
}
38
- return undefined
37
+ return [ [ getReactCompiler ( ) , compilerOptions ] ]
39
38
}
40
39
41
40
const getBabelLoader = (
@@ -67,7 +66,8 @@ const getBabelLoader = (
67
66
hasJsxRuntime : true ,
68
67
reactCompilerPlugins : getReactCompilerPlugins (
69
68
reactCompilerOptions ,
70
- isServer
69
+ isServer ,
70
+ dev
71
71
) ,
72
72
reactCompilerExclude,
73
73
}
@@ -90,11 +90,13 @@ const getReactCompilerLoader = (
90
90
reactCompilerOptions : boolean | ReactCompilerOptions | undefined ,
91
91
cwd : string ,
92
92
isServer : boolean ,
93
- reactCompilerExclude : ( ( excludePath : string ) => boolean ) | undefined
93
+ reactCompilerExclude : ( ( excludePath : string ) => boolean ) | undefined ,
94
+ isDev : boolean
94
95
) => {
95
96
const reactCompilerPlugins = getReactCompilerPlugins (
96
97
reactCompilerOptions ,
97
- isServer
98
+ isServer ,
99
+ isDev
98
100
)
99
101
if ( ! reactCompilerPlugins ) {
100
102
return undefined
0 commit comments