@@ -243,7 +243,12 @@ Click to here to see the config
243
243
</summary >
244
244
Nativewind requires some additional babel config to work correctly. You can see an example of this config below.
245
245
246
+ Tip: Use the web version of storybook to receive compilation and runtime errors that may not bubble up from the mobile simulators.
247
+
246
248
``` js
249
+ // .ondevice/main.ts
250
+ // AND/OR .storybook/main.ts
251
+
247
252
module .exports = {
248
253
addons: [
249
254
/* existing addons,*/
@@ -255,24 +260,84 @@ module.exports = {
255
260
' nativewind' ,
256
261
' react-native-css-interop' ,
257
262
],
258
- babelPresets: [' nativewind/babel' ],
259
263
babelPresetReactOptions: { jsxImportSource: ' nativewind' },
264
+ // If you have a bable.config.js file: this can also be placed there, and removed from here
265
+ babelPresets: [' nativewind/babel' ],
260
266
babelPlugins: [
267
+ // If you have a bable.config.js file: this can also be placed there, and removed from here
261
268
' react-native-reanimated/plugin' ,
269
+ // If you have a bable.config.js file: this can also be placed there, and removed from here
262
270
[
263
271
' @babel/plugin-transform-react-jsx' ,
264
272
{
265
273
runtime: ' automatic' ,
266
274
importSource: ' nativewind' ,
267
275
},
268
- ],
276
+ ],
269
277
],
270
278
},
271
279
},
272
280
],
273
281
};
274
282
```
275
283
284
+ ``` js
285
+ // .ondevice/preview.tsx
286
+ // add the following
287
+ import ' ../styles/global.css'
288
+ ```
289
+
290
+
291
+ ``` js
292
+ // metro.config.js
293
+ const path = require (" path" );
294
+ const { getDefaultConfig } = require (" expo/metro-config" );
295
+ const { withNativeWind } = require (" nativewind/metro" );
296
+ const withStorybook = require (" @storybook/react-native/metro/withStorybook" );
297
+
298
+ const defaultConfig = getDefaultConfig (__dirname );
299
+
300
+ // 👇 important: nativeWindConfig is defined and passed to withStorybook!
301
+ // replace this: module.exports = withNativeWind(config, { input: "./global.css" });
302
+ // with the below (and update your input):
303
+ const nativeWindConfig = withNativeWind (defaultConfig, { input: " ./styles/global.css" });
304
+
305
+ module .exports = withStorybook (nativeWindConfig, {
306
+ // this line helps you switch between app and storybook using variable in package.json script,
307
+ // and changes to your app's main entry point.
308
+ enabled: process .env .EXPO_PUBLIC_STORYBOOK_ENABLED === " true" ,
309
+ configPath: path .resolve (__dirname , " ./.ondevice" ),
310
+ onDisabledRemoveStorybook: true ,
311
+ });
312
+ ```
313
+
314
+
315
+
316
+ ``` js
317
+ // babel.config.js
318
+ module .exports = function (api ) {
319
+ api .cache (true );
320
+ return {
321
+ presets: [
322
+ [" babel-preset-expo" , { jsxImportSource: " nativewind" }],
323
+ " nativewind/babel" ,
324
+ ],
325
+ plugins: [
326
+ [" babel-plugin-react-docgen-typescript" , { exclude: " node_modules" }],
327
+ ' react-native-reanimated/plugin' ,
328
+ [
329
+ ' @babel/plugin-transform-react-jsx' ,
330
+ {
331
+ runtime: ' automatic' ,
332
+ importSource: ' nativewind' ,
333
+ },
334
+ ],
335
+ ],
336
+ };
337
+ };
338
+
339
+ ```
340
+
276
341
</details >
277
342
</td >
278
343
</tr >
0 commit comments