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.
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.
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 shiki, 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.
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.
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.
Now you can create mdx files using codehike.
Markdown (.md) files should also work.
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.
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 shiki, 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.
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.
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.
Now you can create mdx files using codehike.
Markdown (.md) files should also work.
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.