Skip to content

Commit

Permalink
docs: added how-to-add-editor-with-nextjs.md (#446)
Browse files Browse the repository at this point in the history
  • Loading branch information
makhnatkin authored Oct 25, 2024
1 parent 6693eb0 commit e1fc6c3
Showing 1 changed file with 74 additions and 0 deletions.
74 changes: 74 additions & 0 deletions docs/how-to-add-editor-with-nextjs.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,74 @@
## Connection and Configuration
This document provides instructions for configuring Webpack and Turbopack to avoid issues related to the 'fs' module and for connecting the editor on the nextjs client side.

### Issue with 'fs' Module Not Found
In order for the `diplodoc/transform` process to function correctly, please add the [webpack resolve-fallbacks](https://webpack.js.org/configuration/resolve/#resolvefallback).

#### Webpack Configuration

Add the following code to your Webpack configuration:

```javascript
module.exports = {
webpack: {
configure: (webpackConfig) => {
webpackConfig.resolve.fallback = {
fs: false,
process: false,
path: false,
};
return webpackConfig;
},
},
};
```

#### Turbopack Configuration

If you are using Turbopack, set up the `resolveAlias` as follows:

```
experimental: {
turbo: {
resolveAlias: {
fs: './stubs/fs.js',
},
},
},
```

Code for stubs/fs.js

```
let fs;
if (typeof window === 'undefined') {
fs = require('node:fs');
} else {
fs = {};
}
module.exports = fs;
```

### Server-Side Rendering (SSR)

Since the editor uses [ProseMirror](https://prosemirror.net) and [CodeMirror](https://codemirror.net) libraries that depend on working with the DOM on the client side, errors may occur during the build process. Use the following method to load the editor on the client side:

```
import dynamic from 'next/dynamic';
...
const MarkdownEditor = dynamic(
() =>
import('./MarkdownEditor').then(
(mod) => mod.MarkdownEditor,
),
{
ssr: false,
},
);
```


These configurations will help you correctly connect and work with the editor, preventing errors related to the absence of server modules on the client side.

0 comments on commit e1fc6c3

Please sign in to comment.