Skip to content

Commit

Permalink
setup mdx import, demo with README, storybook
Browse files Browse the repository at this point in the history
  • Loading branch information
eric-burel committed Jun 18, 2020
1 parent 889c909 commit a8b7d91
Show file tree
Hide file tree
Showing 8 changed files with 511 additions and 14 deletions.
14 changes: 14 additions & 0 deletions .storybook/main.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,20 @@ module.exports = {
// add magic imports and isomorphic imports to Storybook
const withVulcan = extendWebpackConfig("client")(config);

// add mdx support
// @see https://mdxjs.com/getting-started/webpack
withVulcan.module.rules.push({
test: /\.mdx?$/,
use: ["babel-loader", "@mdx-js/loader"],
});
// Bypass interference with Storybook doc, which already set a conflicting rule for .md import
// @see https://github.com/storybookjs/storybook/issues/7644#issuecomment-592536159
withVulcan.module.rules = [
...withVulcan.module.rules.filter(
(rule) => rule.test.source !== "\\.md$"
),
];

// add bundle analyzer
withVulcan.plugins = (withVulcan.plugins || []).concat(plugins);

Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# Vulcan Next Starter

![vulcan-next-starter banner](https://github.com/VulcanJS/vulcan-next-starter/blob/devel/public/vulcan-next-starter-banner_800.png)
![vulcan-next-starter banner](https://raw.githubusercontent.com/VulcanJS/vulcan-next-starter/devel/public/vulcan-next-starter-banner_800.png)

**WORK IN PROGRESS**

Expand Down
14 changes: 12 additions & 2 deletions docs/features.md
Original file line number Diff line number Diff line change
Expand Up @@ -100,6 +100,14 @@ More broadly, it is related to the impossibility of [reading static files in Nex

`lang` attribute is set automatically on `<html>` during server-render

## MDX support

Get started by reading [MDXJS official doc](https://mdxjs.com/).

### MD and MDX import in React

### Loading MD/MDX in Storybook

## Cypress for e2e testing

### TypeScript and vanilla JS (+ESLint)
Expand Down Expand Up @@ -250,11 +258,13 @@ Demo a Mongodb connection with Mongoose (maybe we could find a demo database onl
 ### Others

Redirection demo for private pages => demo a page that is not available for Example, and redirect to home with an HTTP request
Cookies during server render
Remove debug routes from bundle
Pure JS support (no TS), in cypress, in code, in storybook, in jest...
PErformance testing?
A way to debug which files are built in TypeScript
MDX support
Default styling for MDX, using Material UI
Easy opt out of MDX
Prettier config
Doc for the perfect VS Code setup
TypeScript/Eslint security rules
Expand All @@ -265,4 +275,4 @@ USe ES6 in webpack configs, next.config (see electron-react-boilerplate for a de
Reproduction of various small issues
Mock of next packages from storybook, in jest
Efficient plug to Vulcan
Define Vulcan package standard
Define Vulcan package standard
7 changes: 6 additions & 1 deletion next.config.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
const flowRight = require("lodash/flowRight");
const { extendNextConfig } = require("./packages/@vulcan/next"); // TODO: load from @vulcan/next when it's on NPM
const withMDX = require("@next/mdx")({ extension: /\.mdx?$/ });

const flowRight = require("lodash/flowRight");
const debug = require("debug")("vns:next");

// fooBar => FOO_BAR
Expand Down Expand Up @@ -53,8 +55,11 @@ module.exports = (phase, { defaultConfig }) => {
extendedConfig = withBundleAnalyzer(extendedConfig);
}

// To support markdown import
extendedConfig.pageExtensions = ["js", "jsx", "md", "mdx", "ts", "tsx"];
extendedConfig = flowRight([
withPkgInfo,
withMDX,
// add other wrappers here
])(extendedConfig);

Expand Down
2 changes: 2 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,8 @@
"@apollo/react-ssr": "3.1.3",
"@apollo/react-testing": "3.1.4",
"@material-ui/core": "^4.10.2",
"@mdx-js/loader": "^1.6.6",
"@next/mdx": "^9.4.4",
"apollo-cache-inmemory": "1.6.6",
"apollo-client": "2.6.9",
"apollo-link": "1.2.14",
Expand Down
9 changes: 8 additions & 1 deletion src/components/home/home.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,12 @@
import "~/types/mdx.d.ts"; // TODO: load this automatically
import Readme from "../../../README.md";
export default () => (
<div>
<h1>Vulcan Next Starter</h1>
<h1>Welcome to Vulcan Next Starter</h1>
<p>
Below, find the readme loaded from an MD file using{" "}
<a href="https://mdxjs.com/">MDXJS</a>
</p>
<Readme />
</div>
);
9 changes: 9 additions & 0 deletions src/types/mdx.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
// @see https://mdxjs.com/advanced/typescript
declare module "*.mdx" {
let MDXComponent: (props: any) => JSX.Element;
export default MDXComponent;
}
declare module "*.md" {
let MDXComponent: (props: any) => JSX.Element;
export default MDXComponent;
}
Loading

0 comments on commit a8b7d91

Please sign in to comment.