@@ -7,39 +7,47 @@ import type { RuleSetRule } from '@rspack/core';
77 */
88export const REACT_NATIVE_CODEGEN_RULES : RuleSetRule = {
99 test : / (?: ^ | [ \\ / ] ) (?: N a t i v e \w + | ( \w + ) N a t i v e C o m p o n e n t ) \. [ j t ] s x ? $ / ,
10- rules : [
11- {
12- test : / \. t s x ? $ / ,
13- use : [
10+ use : {
11+ loader : 'babel-loader' ,
12+ options : {
13+ babelrc : false ,
14+ configFile : false ,
15+ parserOpts : {
16+ // hermes-parser strips all comments so the information about flow pragma is lost
17+ // assume flow when dealing with JS files as a workaround
18+ flow : 'all' ,
19+ } ,
20+ plugins : [
21+ 'babel-plugin-syntax-hermes-parser' ,
22+ [ '@babel/plugin-syntax-typescript' , false ] ,
23+ '@react-native/babel-plugin-codegen' ,
24+ ] ,
25+ // config merging reference: https://babeljs.io/docs/options#pluginpreset-entries
26+ overrides : [
1427 {
15- loader : 'babel-loader' ,
16- options : {
17- babelrc : false ,
18- configFile : false ,
19- plugins : [
28+ test : / \. t s $ / ,
29+ plugins : [
30+ [
2031 '@babel/plugin-syntax-typescript' ,
21- '@react-native/babel-plugin-codegen' ,
32+ { isTSX : false , allowNamespaces : true } ,
2233 ] ,
23- } ,
34+ ] ,
2435 } ,
25- ] ,
26- } ,
27- {
28- test : / \. j s x ? $ / ,
29- use : [
3036 {
31- loader : 'babel-loader' ,
32- options : {
33- babelrc : false ,
34- configFile : false ,
35- plugins : [
36- 'babel-plugin-syntax-hermes-parser' ,
37- '@react-native/babel-plugin-codegen' ,
37+ test : / \. t s x $ / ,
38+ plugins : [
39+ [
40+ '@babel/plugin-syntax-typescript' ,
41+ { isTSX : true , allowNamespaces : true } ,
3842 ] ,
39- } ,
43+ ] ,
4044 } ,
4145 ] ,
46+ // source maps are usually set based on the devtool option in config
47+ // Re.Pack templates disable the devtool by default and the flag in loader is not set
48+ // we need to enable sourcemaps for the loader explicitly here
49+ sourceMaps : true ,
4250 } ,
43- ] ,
51+ } ,
4452 type : 'javascript/auto' ,
4553} ;
0 commit comments