$ npm install gatsby-remark-import-code
Use it together with gatsby-plugin-mdx. In gatsby-config.js
:
module.exports = {
plugins: [
{
resolve: `gatsby-plugin-mdx`,
options: {
gatsbyRemarkPlugins: [`gatsby-remark-import-code`]
}
}
]
};
It transforms md/mdx code blocks from this:
```js file=./hello-world.js
```
into:
```js
function helloWorld() {
return "hello world";
}
```