-
Notifications
You must be signed in to change notification settings - Fork 13
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
docs: added how-to-add-editor-with-nextjs.md (#446)
- Loading branch information
1 parent
6693eb0
commit e1fc6c3
Showing
1 changed file
with
74 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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. | ||
|