Skip to content

Commit ee1aacb

Browse files
committed
feat: Add MDX support for Expo
1 parent 14b0892 commit ee1aacb

File tree

8 files changed

+1236
-15
lines changed

8 files changed

+1236
-15
lines changed
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
import MarkdownScreen from '@app/core/screens/MarkdownScreen'
2+
3+
export default MarkdownScreen

apps/expo/metro.config.js

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,5 +21,9 @@ config.resolver.nodeModulesPaths = [
2121
// 3. Force Metro to resolve (sub)dependencies only from the `nodeModulesPaths`
2222
// config.resolver.disableHierarchicalLookup = true;
2323

24+
// 4. Add .md & .mdx files to the file extensions Metro will handle
25+
config.resolver.sourceExts.push('md', 'mdx');
26+
config.transformer.babelTransformerPath = require.resolve('./transformer.js');
27+
2428
// Export the modified config
2529
module.exports = config;

apps/expo/package.json

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,9 +4,11 @@
44
"private": true,
55
"main": "index.js",
66
"dependencies": {
7+
"@bacons/mdx": "^0.2.0",
78
"@expo/metro-runtime": "^3.1.1",
89
"expo": "^50.0.1",
910
"expo-constants": "~15.4.5",
11+
"expo-image": "~1.10.6",
1012
"expo-linking": "~6.2.2",
1113
"expo-router": "~3.4.4",
1214
"expo-status-bar": "~1.11.1",
@@ -15,8 +17,7 @@
1517
"react-native": "0.73.2",
1618
"react-native-safe-area-context": "4.8.2",
1719
"react-native-screens": "~3.29.0",
18-
"react-native-web": "~0.19.6",
19-
"expo-image": "~1.10.6"
20+
"react-native-web": "~0.19.6"
2021
},
2122
"devDependencies": {
2223
"@babel/core": "^7.19.3",

apps/expo/transformer.js

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
const upstreamTransformer = require('@expo/metro-config/babel-transformer');
2+
const MdxTransformer = require("@bacons/mdx/metro-transformer");
3+
4+
module.exports.transform = async (props) => {
5+
// Then pass it to the upstream transformer.
6+
return upstreamTransformer.transform(
7+
// Transpile MDX first.
8+
await MdxTransformer.transform(props)
9+
);
10+
};

features/app-core/mdx/readme.mdx

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
import { Image } from '../components/Image'
2+
3+
<Image
4+
src={require('../assets/aetherspaceLogo.png')}
5+
style={{ marginBottom: 20 }}
6+
width={60}
7+
height={60}
8+
/>
9+
10+
# Universal Expo + Next.js App Router Starter, with MDX
11+
12+
A minimal starter for a **universal Expo + Next.js app** with their respective app routers.
13+
14+
It's a good starting point if you want to:
15+
16+
- ✅ make use of _app-dir file based routing_ in expo and next.js
17+
- ✅ have a _minimal monorepo setup_ with Typescript but no monorepo tool yet
18+
- ✅ leave *all other tech choices* for e.g. styling, dbs, component libs, etc. *up to you*
19+
20+
> Need a more robust, Fully-Stacked, Full-Product, Universal App Setup? Check out **[Aetherspace](https://github.com/Aetherspace/green-stack-starter-demo#readme)**

features/app-core/screens/HomeScreen.tsx

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ const HomeScreen = () => {
1313
<Text style={styles.subtitle}>Open HomeScreen.tsx in features/app-core/screens to start working on your app</Text>
1414
<Link href="/subpages/aetherspace" style={styles.link}>Test navigation</Link>
1515
<Link href="/images" style={styles.link}>Test images</Link>
16+
<Link href="/markdown" style={styles.link}>Test markdown</Link>
1617
</View>
1718
)
1819
}
Lines changed: 92 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,92 @@
1+
import React from 'react'
2+
import { StyleSheet, View } from 'react-native'
3+
import { MDXStyles } from '@bacons/mdx'
4+
import { Link } from '../navigation/Link' // @ts-ignore
5+
import ReadMe from '../mdx/readme.mdx'
6+
7+
/* --- <MarkdownScreen/> --------------------------------------------------------------------------- */
8+
9+
const MarkdownScreen = () => {
10+
return (
11+
<View style={styles.container}>
12+
<Link
13+
href="/"
14+
style={{ ...styles.backButton, ...styles.link, textDecorationLine: 'none' }}
15+
>
16+
{`< Back`}
17+
</Link>
18+
<MDXStyles
19+
h1={styles.h1}
20+
h2={styles.h2}
21+
p={styles.p}
22+
li={styles.li}
23+
blockquote={styles.blockquote}
24+
a={styles.link}
25+
>
26+
<ReadMe />
27+
</MDXStyles>
28+
</View>
29+
)
30+
}
31+
32+
/* --- Styles ---------------------------------------------------------------------------------- */
33+
34+
const styles = StyleSheet.create({
35+
container: {
36+
flex: 1,
37+
justifyContent: 'center',
38+
alignItems: 'flex-start',
39+
padding: 24,
40+
},
41+
backButton: {
42+
position: 'absolute',
43+
top: 16,
44+
left: 16,
45+
},
46+
subtitle: {
47+
marginTop: 8,
48+
marginBottom: 16,
49+
fontSize: 16,
50+
textAlign: 'center',
51+
},
52+
h1: {
53+
fontSize: 24,
54+
fontWeight: 'bold',
55+
marginBottom: 16,
56+
},
57+
h2: {
58+
fontSize: 20,
59+
fontWeight: 'bold',
60+
marginBottom: 16,
61+
},
62+
p: {
63+
fontSize: 16,
64+
marginBottom: 16,
65+
lineHeight: 22,
66+
},
67+
li: {
68+
fontSize: 16,
69+
marginBottom: 16,
70+
lineHeight: 22,
71+
},
72+
blockquote: {
73+
borderLeftColor: 'lightgray',
74+
borderStyle: 'solid',
75+
borderLeftWidth: 6,
76+
fontSize: 16,
77+
paddingLeft: 16,
78+
paddingTop: 4,
79+
lineHeight: 22,
80+
},
81+
link: {
82+
marginTop: 16,
83+
fontSize: 16,
84+
color: 'blue',
85+
textAlign: 'center',
86+
textDecorationLine: 'underline',
87+
},
88+
})
89+
90+
/* --- Exports --------------------------------------------------------------------------------- */
91+
92+
export default MarkdownScreen

0 commit comments

Comments
 (0)