@@ -807,51 +807,21 @@ function bindingToApi(
807
807
originalNextConfig : NextConfigComplete ,
808
808
projectPath : string
809
809
) : Record < string , any > {
810
- let nextConfig = { ...( originalNextConfig as NextConfigComplete ) }
810
+ let nextConfig = { ...originalNextConfig }
811
811
812
812
const reactCompilerOptions = nextConfig . experimental ?. reactCompiler
813
813
814
- // It is not easy to set the rules inside of rust as resolving, and passing the context identical to the webpack
815
- // config is bit hard, also we can reuse same codes between webpack config in here.
814
+ // TODO: Merge this with `crates/next-core/src/next_shared/webpack_rules/babel.rs` so that we're
815
+ // not configuring babel in two different places (potentially causing it to run twice)
816
816
if ( reactCompilerOptions ) {
817
817
const options : ReactCompilerOptions =
818
818
typeof reactCompilerOptions === 'object' ? reactCompilerOptions : { }
819
- const ruleKeys = [ '*.ts' , '*.js' , '*.jsx' , '*.tsx' ]
820
- if (
821
- Object . keys ( nextConfig ?. turbopack ?. rules ?? { } ) . some ( ( key ) =>
822
- ruleKeys . includes ( key )
823
- )
824
- ) {
825
- Log . warn (
826
- "The React Compiler cannot be enabled automatically because 'turbopack.rules' contains " +
827
- "a rule for '*.ts', '*.js', '*.jsx', and '*.tsx'. Remove this rule, or add " +
828
- "'babel-loader' and 'babel-plugin-react-compiler' to the Turbopack configuration " +
829
- 'manually.'
830
- )
831
- } else {
832
- nextConfig . turbopack ??= { }
833
- nextConfig . turbopack . conditions ??= { }
834
- nextConfig . turbopack . rules ??= { }
835
-
836
- for ( const key of ruleKeys ) {
837
- nextConfig . turbopack . conditions [ `#reactCompiler/${ key } ` ] = {
838
- all : [
839
- 'browser' ,
840
- { not : 'foreign' } ,
841
- {
842
- path : key ,
843
- content :
844
- options . compilationMode === 'annotation'
845
- ? / [ ' " ] u s e m e m o [ ' " ] /
846
- : ! options . compilationMode ||
847
- options . compilationMode === 'infer'
848
- ? // Matches declaration or useXXX or </ (closing jsx) or /> (self closing jsx)
849
- / [ ' " ] u s e m e m o [ ' " ] | \W u s e [ A - Z ] | < \/ | \/ > /
850
- : undefined ,
851
- } ,
852
- ] ,
853
- }
854
- nextConfig . turbopack . rules [ `#reactCompiler/${ key } ` ] = {
819
+ nextConfig . turbopack = {
820
+ ...originalNextConfig . turbopack ,
821
+ rules : {
822
+ ...originalNextConfig . turbopack . rules ,
823
+ // assumption: there is no collision with this glob key
824
+ '{*.{js,jsx,ts,tsx,cjs,mjs,mts,cts},react-compiler-builtin-rule}' : {
855
825
loaders : [
856
826
getReactCompilerLoader (
857
827
reactCompilerOptions ,
@@ -861,8 +831,24 @@ function bindingToApi(
861
831
/* reactCompilerExclude */ undefined
862
832
) ,
863
833
] ,
864
- }
865
- }
834
+ condition : {
835
+ all : [
836
+ 'browser' ,
837
+ { not : 'foreign' } ,
838
+ {
839
+ content :
840
+ options . compilationMode === 'annotation'
841
+ ? / [ ' " ] u s e m e m o [ ' " ] /
842
+ : ! options . compilationMode ||
843
+ options . compilationMode === 'infer'
844
+ ? // Matches declaration or useXXX or </ (closing jsx) or /> (self closing jsx)
845
+ / [ ' " ] u s e m e m o [ ' " ] | \W u s e [ A - Z ] | < \/ | \/ > /
846
+ : undefined ,
847
+ } ,
848
+ ] ,
849
+ } ,
850
+ } ,
851
+ } ,
866
852
}
867
853
}
868
854
@@ -948,17 +934,6 @@ function bindingToApi(
948
934
turbopack . rules = serializeTurbopackRules ( turbopack . rules )
949
935
}
950
936
951
- const conditions : ( typeof nextConfig ) [ 'turbopack' ] [ 'conditions' ] =
952
- turbopack . conditions
953
- if ( conditions ) {
954
- const serializedConditions : { [ key : string ] : SerializedRuleCondition } =
955
- { }
956
- for ( const [ key , value ] of Object . entries ( conditions ) ) {
957
- serializedConditions [ key ] = serializeRuleCondition ( value )
958
- }
959
- turbopack . conditions = serializedConditions
960
- }
961
-
962
937
nextConfigSerializable . turbopack = turbopack
963
938
}
964
939
0 commit comments