Skip to content

Commit c8c3a2f

Browse files
authored
Merge pull request #96 from rwitchell/main
Update Tailwind / Nativewind information in readme
2 parents 02e9f63 + 0be498a commit c8c3a2f

File tree

1 file changed

+67
-2
lines changed

1 file changed

+67
-2
lines changed

README.md

+67-2
Original file line numberDiff line numberDiff line change
@@ -243,7 +243,12 @@ Click to here to see the config
243243
</summary>
244244
Nativewind requires some additional babel config to work correctly. You can see an example of this config below.
245245

246+
Tip: Use the web version of storybook to receive compilation and runtime errors that may not bubble up from the mobile simulators.
247+
246248
```js
249+
// .ondevice/main.ts
250+
// AND/OR .storybook/main.ts
251+
247252
module.exports = {
248253
addons: [
249254
/*existing addons,*/
@@ -255,24 +260,84 @@ module.exports = {
255260
'nativewind',
256261
'react-native-css-interop',
257262
],
258-
babelPresets: ['nativewind/babel'],
259263
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'],
260266
babelPlugins: [
267+
// If you have a bable.config.js file: this can also be placed there, and removed from here
261268
'react-native-reanimated/plugin',
269+
// If you have a bable.config.js file: this can also be placed there, and removed from here
262270
[
263271
'@babel/plugin-transform-react-jsx',
264272
{
265273
runtime: 'automatic',
266274
importSource: 'nativewind',
267275
},
268-
],
276+
],
269277
],
270278
},
271279
},
272280
],
273281
};
274282
```
275283

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+
276341
</details>
277342
</td>
278343
</tr>

0 commit comments

Comments
 (0)