Skip to content

Commit a99411a

Browse files
Merge pull request FormidableLabs#689 from FormidableLabs/rewrite/add-webpack-mdx
Rewrite: add webpack mdx
2 parents 2ec9bf7 + 606da2b commit a99411a

File tree

7 files changed

+97
-9
lines changed

7 files changed

+97
-9
lines changed

.babelrc

+1-2
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,7 @@
22
"presets": ["@babel/preset-env", "@babel/preset-react"],
33
"plugins": [
44
"@babel/plugin-proposal-object-rest-spread",
5-
"@babel/plugin-proposal-class-properties",
6-
"babel-plugin-emotion"
5+
"@babel/plugin-proposal-class-properties"
76
],
87
"env": {
98
"esm": {

.gitignore

+8-1
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,9 @@
11
node_modules
2-
yarn.lock
2+
yarn.lock
3+
package-lock.json
4+
dist
5+
lib
6+
es
7+
*.log
8+
.DS_Store
9+
.vscode

index.html

+9
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
<!DOCTYPE html>
2+
<html>
3+
<head>
4+
<title>Getting Started - Spectacle</title>
5+
</head>
6+
<body>
7+
<div id="root"></div>
8+
</body>
9+
</html>

index.js

+8-2
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,12 @@
11
import React from 'react';
22
import { render } from 'react-dom';
3+
import MDXDocument from './test.mdx';
34

4-
import Presentation from './example/src';
5+
/**
6+
* Experiment to test MDX -> JSX transpilation through babel.
7+
*
8+
* Outputs MDXDocument, changing MDXDocument will cause webpack
9+
* to hot-reload with new contents.
10+
*/
511

6-
render(<Presentation />, document.getElementById('root'));
12+
render(<MDXDocument />, document.getElementById('root'));

package.json

+19-4
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,8 @@
1212
"prettier": "prettier \"**/*.{js,json,ts,css,md}\"",
1313
"prettier-fix": "npm run prettier -- --write",
1414
"deploy": "",
15-
"start": "",
15+
"start": "builder run --env \"{\\\"BABEL_ENV\\\":\\\"esm\\\"}\" build-wds-base -- --port=3000 --hot",
16+
"build-wds-base": "webpack-dev-server",
1617
"test": "jest --verbose",
1718
"check": ""
1819
},
@@ -22,25 +23,39 @@
2223
"type": "git",
2324
"url": "https://github.com/FormidableLabs/spectacle.git"
2425
},
25-
"dependencies": {},
26+
"browserslist": "> 0.25%, not dead",
2627
"peerDependencies": {
2728
"prop-types": "^15.6.2",
2829
"react": "^16.7.0",
2930
"react-dom": "^16.7.0"
3031
},
3132
"devDependencies": {
33+
"@babel/cli": "^7.4.4",
34+
"@babel/core": "^7.4.5",
35+
"@babel/plugin-proposal-class-properties": "^7.4.4",
36+
"@babel/plugin-proposal-object-rest-spread": "^7.4.4",
37+
"@babel/polyfill": "^7.4.4",
38+
"@babel/preset-env": "^7.4.5",
39+
"@babel/preset-react": "^7.0.0",
40+
"@mdx-js/loader": "^1.0.0-rc.4",
41+
"babel-loader": "^8.0.6",
42+
"builder": "^4.0.0",
3243
"eslint": "^4.19.0",
3344
"eslint-config-formidable": "^3.0.0",
3445
"eslint-config-prettier": "^2.9.0",
3546
"eslint-plugin-filenames": "^1.2.0",
3647
"eslint-plugin-import": "^2.9.0",
3748
"eslint-plugin-react": "^7.7.0",
49+
"html-webpack-plugin": "^3.2.0",
3850
"prettier": "^1.15.3",
3951
"prop-types": "^15.6.2",
4052
"raw-loader": "^1.0.0",
4153
"react": "^16.7.0",
4254
"react-dom": "^16.7.0",
4355
"tslint": "^5.12.1",
44-
"typescript": "^3.2.2"
56+
"typescript": "^3.2.2",
57+
"webpack": "^4.33.0",
58+
"webpack-cli": "^3.3.4",
59+
"webpack-dev-server": "^3.7.1"
4560
}
46-
}
61+
}

test.mdx

+23
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
<!-- This is an MDX file that is imported in index.js and transpiled to
2+
JSX and then rendered, feel free to change this! -->
3+
4+
# Hello, _world_!
5+
6+
Below is an example of JSX embedded in Markdown. <br /> **Kara and dom were successful!**
7+
8+
<div style={{ padding: '20px', backgroundColor: 'aliceblue' }}>
9+
<h3>This is JSX</h3>
10+
</div>
11+
12+
- One ah ah ah
13+
- Two ah ah ah
14+
- Two point five
15+
- Three
16+
17+
## Code snippet test
18+
19+
const hello = "hi";
20+
21+
```js
22+
const hi = 'hello';
23+
```

webpack.config.js

+29
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
const path = require('path');
2+
const HtmlWebpackPlugin = require('html-webpack-plugin');
3+
4+
module.exports = {
5+
entry: './index.js',
6+
output: {
7+
path: path.join(__dirname, 'dist'),
8+
filename: 'bundle.js'
9+
},
10+
module: {
11+
rules: [
12+
{
13+
test: /\.js$/,
14+
use: {
15+
loader: 'babel-loader',
16+
options: {
17+
presets: ['@babel/preset-env']
18+
}
19+
}
20+
},
21+
{ test: /\.mdx?$/, use: ['babel-loader', '@mdx-js/loader'] }
22+
]
23+
},
24+
plugins: [
25+
new HtmlWebpackPlugin({
26+
template: `./index.html`
27+
})
28+
]
29+
};

0 commit comments

Comments
 (0)