Skip to content

Commit ad25c6b

Browse files
jeetissjaredpalmer
authored andcommitted
Mdx plugin improvements (#732)
* resolving path to @mdx-js/tag, fix loader options * del peerDep, improve readme * add example
1 parent c0013d4 commit ad25c6b

12 files changed

Lines changed: 134 additions & 7 deletions

File tree

examples/with-mdx/.gitignore

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
logs
2+
*.log
3+
npm-debug.log*
4+
.DS_Store
5+
6+
coverage
7+
node_modules
8+
build
9+
public/static
10+
.env.*.local

examples/with-mdx/package.json

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
{
2+
"private": true,
3+
"name": "mdx-razzle",
4+
"scripts": {
5+
"start": "razzle start",
6+
"build": "razzle build",
7+
"test": "razzle test --env=jsdom",
8+
"start:prod": "NODE_ENV=production node build/server.js"
9+
},
10+
"dependencies": {
11+
"express": "^4.15.2",
12+
"razzle": "^2.4.0",
13+
"razzle-plugin-mdx": "^2.4.0",
14+
"react": "^16.0.0",
15+
"react-dom": "^16.0.0",
16+
"remark-emoji": "^2.0.1"
17+
}
18+
}

examples/with-mdx/razzle.config.js

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
'use strict';
2+
3+
const emoji = require('remark-emoji');
4+
5+
module.exports = {
6+
plugins: [
7+
{
8+
name: 'mdx',
9+
options: {
10+
mdPlugins: [emoji],
11+
},
12+
},
13+
],
14+
};

examples/with-mdx/readme.md

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
# MDX + Razzle
2+
3+
```
4+
npm install
5+
npm start
6+
```
7+
8+
[See documentation](https://mdxjs.com/getting-started/razzle)

examples/with-mdx/src/App.js

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
import React from 'react';
2+
import Doc from './example.md';
3+
4+
export default () => <Doc />;

examples/with-mdx/src/client.js

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
import React from 'react';
2+
import { hydrate } from 'react-dom';
3+
import App from './App';
4+
5+
hydrate(<App />, document.getElementById('root'));
6+
7+
if (module.hot) {
8+
module.hot.accept();
9+
}

examples/with-mdx/src/example.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
# :wave: Hello, world!
2+
3+
This is MDX!

examples/with-mdx/src/index.js

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
import express from 'express';
2+
import app from './server';
3+
4+
if (module.hot) {
5+
module.hot.accept('./server', function() {
6+
console.log('🔁 HMR Reloading `./server`...');
7+
});
8+
console.info('✅ Server-side HMR Enabled!');
9+
}
10+
11+
const port = process.env.PORT || 3000;
12+
13+
export default express()
14+
.use((req, res) => app.handle(req, res))
15+
.listen(port, function(err) {
16+
if (err) {
17+
console.error(err);
18+
return;
19+
}
20+
console.log(`> Started on port ${port}`);
21+
});

examples/with-mdx/src/server.js

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
import App from './App';
2+
import React from 'react';
3+
import express from 'express';
4+
import { renderToString } from 'react-dom/server';
5+
6+
const assets = require(process.env.RAZZLE_ASSETS_MANIFEST);
7+
8+
const server = express();
9+
10+
server
11+
.disable('x-powered-by')
12+
.use(express.static(process.env.RAZZLE_PUBLIC_DIR))
13+
.get('/*', (req, res) => {
14+
const markup = renderToString(<App />);
15+
res.send(
16+
// prettier-ignore
17+
`<!doctype html>
18+
<html lang="">
19+
<head>
20+
<meta http-equiv="X-UA-Compatible" content="IE=edge" />
21+
<meta charSet='utf-8' />
22+
<title>Welcome to Razzle</title>
23+
<meta name="viewport" content="width=device-width, initial-scale=1">
24+
${
25+
assets.client.css
26+
? `<link rel="stylesheet" href="${assets.client.css}">`
27+
: ''
28+
}
29+
</head>
30+
<body>
31+
<div id="root">${markup}</div>
32+
<script src="${assets.client.js}" defer crossorigin></script>
33+
</body>
34+
</html>`
35+
);
36+
});
37+
38+
export default server;

packages/razzle-plugin-mdx/README.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,13 +5,13 @@ This package contains a plugin for using mdx with Razzle
55
## Usage in Razzle Projects
66

77
```
8-
npm i razzle-plugin-mdx @mdx-js/tag
8+
npm i razzle-plugin-mdx
99
```
1010

1111
or
1212

1313
```
14-
yarn add razzle-plugin-mdx @mdx-js/tag
14+
yarn add razzle-plugin-mdx
1515
```
1616

1717
### Using the plugin with the default options

0 commit comments

Comments
 (0)