44
loading...
This website collects cookies to deliver better user experience
npm install @next/mdx @mdx-js/loader
next.config.js
, configure Next.js to handle MDX files:// next.config.js
const withMDX = require('@next/mdx')({
extension: /\.mdx?$/,
});
module.exports = withMDX({
pageExtensions: ['js', 'jsx', 'mdx'],
});
onions.mdx
file:# Onions
Layers. Onions have layers. Ogres have layers. Onions have layers. You get it? We both have layers.
Oh, you both have layers. Oh. You know, not everybody like onions.
```js
const year = "2001";
const movie = "Shrek";
console.log(`${movie}, ${year}`);
npm run dev
and navigate to /onions
to see the rendered MDX page:remark-prism
package. Then update next.config.js
to include the plugin:// next.config.js
const withMDX = require("@next/mdx")({
extension: /\.mdx?$/,
options: {
remarkPlugins: [require("remark-prism")],
},
});
module.exports = withMDX({
pageExtensions: ["js", "jsx", "mdx"],
});
_document.js
file and linking to the stylesheet in the head:import Document, { Html, Head, Main, NextScript } from "next/document";
class MyDocument extends Document {
render() {
return (
<Html>
<Head>
<link
rel="stylesheet"
href="https://unpkg.com/dracula-prism/dist/css/dracula-prism.css"
></link>
</Head>
<body>
<Main />
<NextScript />
</body>
</Html>
);
}
}
export default MyDocument;
_document.js
file as a stylesheet:<link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/water.css@2/out/dark.css"></link>
styles/globals.css
file sets all padding and margin to zero. I also remove these rules to get some padding and margin back.