Skip to content

Commit 5157621

Browse files
committed
✨ Add with-mdx example
1 parent 1af49ae commit 5157621

15 files changed

+191
-0
lines changed

examples/with-mdx/.eslintrc.js

+19
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
module.exports = {
2+
extends: 'plugin:nullstack/recommended',
3+
rules: {
4+
'nullstack/prettier': [
5+
'warn',
6+
{
7+
// More options at https://prettier.io/docs/en/options
8+
trailingComma: 'all',
9+
tabWidth: 2,
10+
semi: false,
11+
singleQuote: true,
12+
printWidth: 80,
13+
},
14+
{
15+
usePrettierrc: false,
16+
},
17+
],
18+
},
19+
}

examples/with-mdx/.gitignore

+32
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
# See https://help.github.com/articles/ignoring-files/ for more about ignoring files.
2+
3+
# dependencies
4+
/node_modules
5+
/.pnp
6+
.pnp.js
7+
package-lock.json
8+
yarn.lock
9+
pnpm-lock.yaml
10+
11+
# testing
12+
/coverage
13+
14+
# misc
15+
.DS_Store
16+
*.pem
17+
18+
# debug
19+
npm-debug.log*
20+
yarn-debug.log*
21+
yarn-error.log*
22+
.pnpm-debug.log*
23+
24+
# local env files
25+
.env
26+
27+
# vercel
28+
.vercel
29+
30+
# bundle folders
31+
.development/
32+
.production/

examples/with-mdx/README.md

+22
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
# Example app with MDX
2+
3+
This example shows using [MDX](https://github.com/mdx-js/mdx) as top level pages for your Nullstack app.
4+
5+
Based on the [fccoelho7/nullstack-mdx](https://github.com/fccoelho7/nullstack-mdx) with Tailwind ✨
6+
7+
## Deploy your own
8+
9+
Deploy it now with [Vercel](https://vercel.com) or preview on [StackBlitz](https://stackblitz.com):
10+
11+
[![Deploy with Vercel](https://vercel.com/button)](https://vercel.com/new/clone?repository-url=https://github.com/GuiDevloper/nullstack-examples/tree/main/examples/with-mdx&project-name=with-mdx&repo-name=with-mdx&demo-title=Nullstack+withMDX&demo-description=Nullstack+example+with+mdx&demo-url=https://github.com/GuiDevloper/nullstack-examples/tree/main/examples/with-mdx&demo-image=https://nullstack.app/image-1200x630.png)
12+
[![Open in StackBlitz](https://developer.stackblitz.com/img/open_in_stackblitz.svg)](https://stackblitz.com/fork/github/GuiDevloper/nullstack-examples/tree/main/examples/with-mdx?title=Nullstack+WithMDX)
13+
14+
## How to use
15+
16+
Execute [`nulla create`](https://github.com/GuiDevloper/nulla) with [npm](https://docs.npmjs.com/cli/init):
17+
18+
```bash
19+
npx nulla create --example with-mdx with-mdx-app
20+
```
21+
22+
Then deploy it with [Vercel](https://github.com/GuiDevloper/nulla/blob/main/docs/en-US/deploy-vercel.md), [Heroku](https://github.com/GuiDevloper/nulla/blob/main/docs/en-US/deploy-heroku.md) or [Netlify](https://github.com/GuiDevloper/nulla/blob/main/docs/en-US/deploy-netlify.md).

examples/with-mdx/client.ts

+5
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
import Nullstack from 'nullstack'
2+
3+
import Application from './src/Application'
4+
5+
export default Nullstack.start(Application)

examples/with-mdx/package.json

+19
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
{
2+
"private": true,
3+
"devDependencies": {
4+
"nullstack": "0.20.0"
5+
},
6+
"scripts": {
7+
"start": "npx nullstack start",
8+
"build": "npx nullstack build",
9+
"vercel-build": "npm run build && npx nullstack-adapt-vercel"
10+
},
11+
"stackblitz": {
12+
"installDependencies": false,
13+
"startCommand": "npm i [email protected] -D && nullstack-adapt-babel && npm start",
14+
"compileTrigger": "save"
15+
},
16+
"dependencies": {
17+
"@mdx-js/loader": "^2.3.0"
18+
}
19+
}
930 Bytes
Loading

examples/with-mdx/server.ts

+5
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
import Nullstack from 'nullstack'
2+
3+
import Application from './src/Application'
4+
5+
export default Nullstack.start(Application)

examples/with-mdx/src/Application.css

+13
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
* {
2+
padding: 0;
3+
margin: 0;
4+
text-decoration: none;
5+
list-style: none;
6+
box-sizing: border-box;
7+
}
8+
9+
body {
10+
background-color: #111827;
11+
color: #fff;
12+
font-family: sans-serif;
13+
}

examples/with-mdx/src/Application.tsx

+18
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
import './Application.css'
2+
import Nullstack from 'nullstack'
3+
4+
import Home from './Home.mdx'
5+
6+
class Application extends Nullstack {
7+
8+
render() {
9+
return (
10+
<main>
11+
<Home route="/" />
12+
</main>
13+
)
14+
}
15+
16+
}
17+
18+
export default Application

examples/with-mdx/src/Button.css

+8
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
.button {
2+
border-radius: 3px;
3+
border: 1px solid black;
4+
color: black;
5+
padding: 0.5em 1em;
6+
cursor: pointer;
7+
font-size: 1.1em;
8+
}

examples/with-mdx/src/Button.tsx

+4
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
import './Button.css'
2+
export default function Button({ children }) {
3+
return <button class="button">{children}</button>
4+
}

examples/with-mdx/src/Home.mdx

+7
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
import Button from './Button'
2+
3+
# MDX + Nullstack
4+
5+
Look, a button! 👇
6+
7+
<Button>👋 Hello</Button>

examples/with-mdx/src/types.d.ts

+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
declare module '*.mdx'

examples/with-mdx/tsconfig.json

+8
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
{
2+
"compilerOptions": {
3+
"strict": false,
4+
"noImplicitAny": false,
5+
"jsx": "preserve",
6+
"lib": ["ES2020", "DOM"]
7+
}
8+
}

examples/with-mdx/webpack.config.js

+30
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
const configs = require('nullstack/webpack.config')
2+
3+
function withMDX(config) {
4+
const mdxRule = {
5+
test: /\.mdx?$/,
6+
use: [
7+
{
8+
loader: '@mdx-js/loader',
9+
options: {
10+
jsxRuntime: 'classic',
11+
pragma: '$runtime.element',
12+
pragmaFrag: '$runtime.fragment',
13+
pragmaImportSource: 'nullstack/runtime',
14+
},
15+
},
16+
],
17+
}
18+
config.module.rules.push(mdxRule)
19+
return config
20+
}
21+
22+
function customConfigs() {
23+
return configs.map((originalConfig) => {
24+
return (...args) => {
25+
return withMDX(originalConfig(...args))
26+
}
27+
})
28+
}
29+
30+
module.exports = customConfigs()

0 commit comments

Comments
 (0)