Skip to content

Commit 9890400

Browse files
authored
fix: split ts & tsx rules in codegen & enable source maps (#819)
* fix: split ts & tsx rules in codegen * fix: reorganize the rules, add missing sourcemap generation * chore: add changset
1 parent c97da24 commit 9890400

File tree

2 files changed

+38
-25
lines changed

2 files changed

+38
-25
lines changed

.changeset/smooth-zebras-hunt.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
"@callstack/repack": patch
3+
---
4+
5+
Fix missing sourcemap generation for codegen related files and configure separate rules for ts & tsx files

packages/repack/src/rules/reactNativeCodegenRules.ts

Lines changed: 33 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -7,39 +7,47 @@ import type { RuleSetRule } from '@rspack/core';
77
*/
88
export const REACT_NATIVE_CODEGEN_RULES: RuleSetRule = {
99
test: /(?:^|[\\/])(?:Native\w+|(\w+)NativeComponent)\.[jt]sx?$/,
10-
rules: [
11-
{
12-
test: /\.tsx?$/,
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: /\.ts$/,
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: /\.jsx?$/,
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: /\.tsx$/,
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

Comments
 (0)