💎一站式轻松地调用各大LLM模型接口,支持GPT4、智谱、星火、月之暗面及文生图 广告
[TOC] ## 概述 借助 vite 可以把 带 使用 `import` 的 编译层可以给html 使用的 ``` > pnpm init > pnpm install --save-dev vite ``` 目录格式 ``` ├── src │ ├── app.js │ └── index.html ├── package.json └── vite.config.js ``` <details> <summary>app.js</summary> ``` import * as Y from 'yjs'; // 创建一个 Yjs 文档 const ydoc = new Y.Doc(); // 如果解析成功,则会正常输出 clientid console.log('Client ID:', ydoc.clientID); ``` </details> <details> <summary>index.html</summary> ``` <!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8"> <meta name="viewport" content="width=device-width, initial-scale=1.0"> <title>Document</title> </head> <body> <textarea id="editor"></textarea> <script type="module" src="./app.js"></script> </body> </html> ``` </details> <details> <summary>package.json</summary> ``` { "name": "jj-demo", "version": "1.0.0", "description": "", "main": "index.js", "scripts": { "dev": "vite", "build": "vite build", "preview": "vite preview", "test": "echo \"Error: no test specified\" && exit 1" }, "keywords": [], "author": "", "license": "ISC", "devDependencies": { "vite": "^5.4.8" }, "dependencies": { "yjs": "^13.6.19" } } ``` </details> <details> <summary>vite.config.js</summary> ``` import { defineConfig } from 'vite' import path from 'path' export default defineConfig({ root: 'src', build: { outDir: '../dist', }, resolve: { alias: { '@': path.resolve(__dirname, './src') } } }) ``` </details> 运行 ``` pnpm run dev // or pnpm run build ```