8
8
- [ Setup React Native CSS modules with Less support] ( setup-less.md )
9
9
- [ Setup React Native CSS modules with Stylus support] ( setup-stylus.md )
10
10
11
- ### Step 2: configure ` .babelrc ` and ` rn-cli.config.js `
11
+ ### Step 2: Modify Babel configuration
12
12
13
13
In your project's root folder:
14
14
@@ -49,26 +49,6 @@ module.exports = function(api) {
49
49
};
50
50
```
51
51
52
- Configure ` rn-cli.config.js ` to use a custom transformer file and add more extensions:
53
-
54
- ``` js
55
- const { getDefaultConfig } = require (" metro-config" );
56
-
57
- module .exports = (async () => {
58
- const {
59
- resolver: { sourceExts }
60
- } = await getDefaultConfig ();
61
- return {
62
- transformer: {
63
- babelTransformerPath: require .resolve (" ./transformer.js" )
64
- },
65
- resolver: {
66
- sourceExts: [... sourceExts, " css" , " scss" , " sass" ]
67
- }
68
- };
69
- })();
70
- ```
71
-
72
52
---
73
53
74
54
#### For React Native v0.56 or older
@@ -90,20 +70,9 @@ Add more extensions to `.babelrc`:
90
70
}
91
71
```
92
72
93
- Configure ` rn-cli.config.js ` to use a custom transformer file and add more extensions:
94
-
95
- ``` js
96
- module .exports = {
97
- getTransformModulePath () {
98
- return require .resolve (" ./transformer.js" );
99
- },
100
- getSourceExts () {
101
- return [" js" , " jsx" , " css" , " scss" , " sass" ];
102
- }
103
- };
104
- ```
73
+ ---
105
74
106
- #### Expo SDK v30.0.0 or older
75
+ #### For Expo SDK v30.0.0 or older
107
76
108
77
Add more extensions to ` .babelrc ` :
109
78
@@ -122,7 +91,54 @@ Add more extensions to `.babelrc`:
122
91
}
123
92
```
124
93
125
- Instead of adding the ` rn-cli.config.js ` file, you need to add this to ` app.json ` :
94
+ ### Step 3: Modify Metro bundler configuration
95
+
96
+ In your project's root folder:
97
+
98
+ #### For React Native v0.57 or newer / Expo SDK v31.0.0 or newer
99
+
100
+ Configure ` metro.config.js ` to use a custom transformer file and add more extensions:
101
+
102
+ ``` js
103
+ const { getDefaultConfig } = require (" metro-config" );
104
+
105
+ module .exports = (async () => {
106
+ const {
107
+ resolver: { sourceExts }
108
+ } = await getDefaultConfig ();
109
+ return {
110
+ transformer: {
111
+ babelTransformerPath: require .resolve (" ./transformer.js" )
112
+ },
113
+ resolver: {
114
+ sourceExts: [... sourceExts, " css" , " scss" , " sass" ]
115
+ }
116
+ };
117
+ })();
118
+ ```
119
+
120
+ ---
121
+
122
+ #### For React Native v0.56 or older
123
+
124
+ Configure ` rn-cli.config.js ` to use a custom transformer file and add more extensions:
125
+
126
+ ``` js
127
+ module .exports = {
128
+ getTransformModulePath () {
129
+ return require .resolve (" ./transformer.js" );
130
+ },
131
+ getSourceExts () {
132
+ return [" js" , " jsx" , " css" , " scss" , " sass" ];
133
+ }
134
+ };
135
+ ```
136
+
137
+ ---
138
+
139
+ #### For Expo SDK v30.0.0 or older
140
+
141
+ Configure ` app.json ` to use a custom transformer file and add more extensions:
126
142
127
143
``` json
128
144
{
@@ -135,13 +151,16 @@ Instead of adding the `rn-cli.config.js` file, you need to add this to `app.json
135
151
}
136
152
```
137
153
138
- ### Step 3 : configure transformer
154
+ ### Step 4 : configure transformer
139
155
140
156
Create a ` transformer.js ` file:
141
157
142
158
``` js
143
- // For React Native version 0.56 or later
144
- var upstreamTransformer = require (" metro/src/reactNativeTransformer" );
159
+ // For React Native version 0.59 or later
160
+ var upstreamTransformer = require (" metro-react-native-babel-transformer" );
161
+
162
+ // For React Native version 0.56-0.58
163
+ // var upstreamTransformer = require("metro/src/reactNativeTransformer");
145
164
146
165
// For React Native version 0.52-0.55
147
166
// var upstreamTransformer = require("metro/src/transformer");
0 commit comments