Integrate Document Authoring (WYSIWYG library) using Vite
This guide walks you through the process of integrating the Document Authoring — what you see is what you get (WYSIWYG) TypeScript library — into your web application using Vite. By following these steps, you’ll be able to set up in-browser visual editing capabilities without the need for external word processing software.
Creating a new Vite project
npm create vite my-apppnpm create vite my-appyarn create vite my-appbun create vite my-appChange to the newly created project directory:
cd my-appInstalling the library
For a new project, set up the environment to include @nutrient-sdk/document-authoring.
npm i @nutrient-sdk/document-authoringpnpm add @nutrient-sdk/document-authoringyarn add @nutrient-sdk/document-authoringbun add @nutrient-sdk/document-authoringIntegrating into your project
Add an empty
<div>element with apositionset to a value other thanstatic, and with a definedwidthandheight. This will be the target DOM element where the editor will be loaded:<div id="editor" style="position: relative; width: 100%; height: 100vh; border: 1px solid #dcdcdc;"></div>Import the library:
import { createDocAuthSystem } from '@nutrient-sdk/document-authoring';(async () => {const docAuthSystem = await createDocAuthSystem();const editor = await docAuthSystem.createEditor(document.getElementById('editor'), {document: await docAuthSystem.createDocumentFromPlaintext('Hello world!'),});})();
Running the Vite dev server
npm run devpnpm run devyarn run devbun run dev