Debug

Based on Next.js official docs.

Start by installing next and react on an empty directory:


npm install next react react-dom

Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Praesent elementum facilisis leo vel fringilla est ullamcorper eget. At imperdiet dui accumsan sit amet nulla facilities morbi tempus. Praesent elementum facilisis leo vel fringilla. Congue mauris rhoncus aenean vel. Egestas sed tempus urna et pharetra pharetra massa massa ultricies.

Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Praesent elementum facilisis leo vel fringilla est ullamcorper eget. At imperdiet dui accumsan sit amet nulla facilities morbi tempus. Praesent elementum facilisis leo vel fringilla. Congue mauris rhoncus aenean vel. Egestas sed tempus urna et pharetra pharetra massa massa ultricies.

Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Praesent elementum facilisis leo vel fringilla est ullamcorper eget. At imperdiet dui accumsan sit amet nulla facilities morbi tempus. Praesent elementum facilisis leo vel fringilla. Congue mauris rhoncus aenean vel. Egestas sed tempus urna et pharetra pharetra massa massa ultricies.

Step 1

Create a next.config.js file at the root of your project.

Here we use the require("@next/mdx") plugin to set up MDX imports.

Step 1
Step 1
Step 1
Step 1
Step 1
Step 1
Step 1
Step 1
Step 1
Step 1
Step 1

Also, make sure you include "md" and "mdx" on the pageExtensions setting.

After this step, you can use MDX files in your project, but you can't use Code Hike yet.

next.config.js
foo.js
barbarbar.js
bax.js

const withMDX = require("@next/mdx")({
extension: /\.mdx?$/,
options: {
remarkPlugins: [],
},
})
module.exports = withMDX({
pageExtensions: [
"ts", "tsx", "js",
"jsx", "md", "mdx"
],
})

index.css

.scrollycoding {
overflow: auto;
max-height: calc(100vh - 100px);
}

Step 3

To set up Code Hike you need to import the @code-hike/mdx plugin, and add it to the remarkPlugins array in the next.config.js file.

You will also want to import a theme. You can import one from lighter, or make a custom one.

Pass the theme into Code Hike's config object, there are a few more settings you can use, like lineNumbers for example.

Step 4

Then you need to create a pages/_app.js file if you don't have one.

You can find more information about the _app.js file in the Next.js official docs.

pages/_app.js

function MyApp({ Component, pageProps }) {
return <Component {...pageProps} />
}
export default MyApp

Step 5

The pages/_app.js file is where you add global stylesheets in Next.js.

Here we need to import Code Hike's CSS.

Step 5

If you want to customize Code Hike's styles with a global stylesheet make sure to import it after this import to avoid specificity issues.

pages/_app.js
next.config.js

import "@code-hike/mdx/dist/index.css"
function MyApp({ Component, pageProps }) {
return <Component {...pageProps} />
}
export default MyApp

Step 6

Now you can create mdx files using codehike.

Markdown (.md) files should also work.

next.config.js
pages/my.mdx

# Hello
Lorem ipsum dolor sit amet.
```python hello.py
print("Rendered with Code Hike")
```
Lorem ipsum dolor sit amet.

Step 1

Create a next.config.js file at the root of your project.

Here we use the require("@next/mdx") plugin to set up MDX imports.

Also, make sure you include "md" and "mdx" on the pageExtensions setting.

After this step, you can use MDX files in your project, but you can't use Code Hike yet.

Step 3

To set up Code Hike you need to import the @code-hike/mdx plugin, and add it to the remarkPlugins array in the next.config.js file.

You will also want to import a theme. You can import one from lighter, or make a custom one.

Pass the theme into Code Hike's config object, there are a few more settings you can use, like lineNumbers for example.

Step 4

Then you need to create a pages/_app.js file if you don't have one.

You can find more information about the _app.js file in the Next.js official docs.

Step 5

The pages/_app.js file is where you add global stylesheets in Next.js.

Here we need to import Code Hike's CSS.

If you want to customize Code Hike's styles with a global stylesheet make sure to import it after this import to avoid specificity issues.

Step 6

Now you can create mdx files using codehike.

Markdown (.md) files should also work.

next.config.js
foo.js
barbarbar.js
bax.js

const withMDX = require("@next/mdx")({
extension: /\.mdx?$/,
options: {
remarkPlugins: [],
},
})
module.exports = withMDX({
pageExtensions: [
"ts", "tsx", "js",
"jsx", "md", "mdx"
],
})

index.css

.scrollycoding {
overflow: auto;
max-height: calc(100vh - 100px);
}

Step 1
Step 1
Step 1
Step 1
Step 1
Step 1
Step 1
Step 1
Step 1
Step 1
Step 1

Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Praesent elementum facilisis leo vel fringilla est ullamcorper eget. At imperdiet dui accumsan sit amet nulla facilities morbi tempus. Praesent elementum facilisis leo vel fringilla. Congue mauris rhoncus aenean vel. Egestas sed tempus urna et pharetra pharetra massa massa ultricies.

Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Praesent elementum facilisis leo vel fringilla est ullamcorper eget. At imperdiet dui accumsan sit amet nulla facilities morbi tempus. Praesent elementum facilisis leo vel fringilla. Congue mauris rhoncus aenean vel. Egestas sed tempus urna et pharetra pharetra massa massa ultricies.

Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Praesent elementum facilisis leo vel fringilla est ullamcorper eget. At imperdiet dui accumsan sit amet nulla facilities morbi tempus. Praesent elementum facilisis leo vel fringilla. Congue mauris rhoncus aenean vel. Egestas sed tempus urna et pharetra pharetra massa massa ultricies.

Consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Praesent elementum facilisis leo vel fringilla est ullamcorper eget. At imperdiet dui accumsan sit amet nulla facilities morbi tempus. Praesent elementum facilisis leo vel fringilla. Congue mauris rhoncus aenean vel. Egestas sed tempus urna et pharetra pharetra massa massa ultricies.