当前位置: 首页 > news >正文

【Svelte】怎样将 Docusaurus 网站部署到 Svelte 网站的子路径 /docs 下?

To host a Docusaurus site under the/docspath of a Svelte 5 (SvelteKit) project, you have two primary ways to do it.

Method 1: The “Static” Approach (Simplest)

This method involves building your Docusaurus site and placing the output inside SvelteKit’sstaticfolder.

1. Configure Docusaurus

In your Docusaurus project, opendocusaurus.config.jsand update thebaseUrl:

// docusaurus.config.jsexportdefault{title:'My Docs',url:'https://your-domain.com',baseUrl:'/docs/',// CRITICAL: This must match your folder nametrailingSlash:true,// ... rest of config};
2. Build and Move
  1. Build your Docusaurus site:npm run build.
  2. This creates abuildfolder.
  3. In your Svelte 5 project, create a folder:static/docs/.
  4. Copy everything from the Docusaurusbuildfolder into your Svelte project’sstatic/docs/folder.
3. Handling Links in Svelte 5

When linking to your docs from your Svelte components, youmustforce a full page reload so SvelteKit’s router doesn’t try to handle the/docsroute:

<script> // Svelte 5 component </script> <a href="/docs/">Method 2: Deployment Proxy (Best for Production/CI/CD)

If you are using a monorepo or don’t want to manually copy files into thestaticfolder, you should handle this at thehosting level(e.g., Vercel, Netlify, or Nginx).

For Vercel (vercel.json):

If you have two separate projects (one for Svelte, one for Docusaurus), you can use “Rewrites” in your Svelte project’s root:

{"rewrites":[{"source":"/docs/:path*","destination":"https://your-docusaurus-site.vercel.app/docs/:path*"}]}

Note: Docusaurus must still havebaseUrl: '/docs/'configured.


Method 3: Automated Build Script (Recommended)

If you want to keep them in one repository, you can automate the process in yourpackage.json.

  1. Structure:

    /my-monorepo ├── /svelte-app └── /documentation-site
  2. Insvelte-app/package.json, create a build script:

{"scripts":{"build:docs":"cd ../documentation-site && npm run build","copy:docs":"cp -r ../documentation-site/build/* ./static/docs/","build":"npm run build:docs && npm run copy:docs && vite build"}}

Critical Issues to Watch For:

  1. Hydration Errors:If you don’t usedata-sveltekit-reload, SvelteKit will try to render the Docusaurusindex.htmlinside your Svelte layout, which will fail or look broken.
  2. Asset Paths:IfbaseUrlisn’t set to/docs/in Docusaurus, your CSS and JS files will look for/assets/js/...instead of/docs/assets/js/...and return 404s.
  3. Trailing Slashes:Docusaurus prefers trailing slashes. Ensure your links are to/docs/(with the slash) to avoid unnecessary redirects.

Which should you choose?

  • UseMethod 1if you want one single deployment and the docs don’t change very often.
  • UseMethod 2if you want to deploy the docs independently of the main app (faster CI/CD).
http://www.jsqmd.com/news/261543/

相关文章:

  • HsMod炉石插件深度体验指南:55项功能全面解锁游戏新境界
  • 零基础玩转AI对话:Qwen2.5-0.5B保姆级入门教程
  • NVIDIA Profile Inspector终极使用指南:释放显卡隐藏性能的完整教程
  • PaddleOCR-VL水印处理:干扰文本识别优化方法
  • XUnity自动翻译插件终极指南:轻松突破游戏语言障碍
  • 终极指南:如何用HsMod插件彻底改变你的炉石传说体验
  • Qwen2.5-7B性能优化:降低显存占用的5个技巧
  • Qwen3-Embedding-4B功能测评:119种语言的语义搜索表现
  • AntiMicroX终极指南:免费游戏手柄按键映射解决方案
  • AI开发者入门必看:Qwen2.5开源模型多框架部署指南
  • 终极指南:10个smartmontools 7.5磁盘监控实用技巧
  • nmodbus4类库使用教程:核心要点掌握超时重试机制设置
  • ViGEmBus虚拟游戏控制器驱动:Windows游戏兼容的终极解决方案
  • Cute_Animal_For_Kids_Qwen_Image进阶教程:自定义风格与表情
  • DeepSeek-R1模型压缩:从大模型到1.5B的技术路径
  • 解锁华硕ROG笔记本潜能:轻量级性能优化工具完全指南
  • React Native Vision Camera 终极优化指南:从零到专业级性能
  • Supertonic实战指南:66M参数轻量级TTS模型部署教程
  • Android离线人脸识别技术深度解析:从架构设计到落地实践
  • OpenCode快速上手终极指南:3步搞定终端AI编程助手
  • MissionControl完整教程:在Switch上免费使用各类蓝牙控制器
  • 解放你的eSIM:OpenEUICC如何让Android设备真正掌控移动网络
  • 通义千问2.5-0.5B显存优化技巧:GGUF-Q4压缩部署详细步骤
  • 如何在现代PC上重新定义经典游戏体验?
  • AntiMicroX完整指南:用手柄操控任何PC游戏的终极方案
  • 如何快速解决Cursor试用限制问题:面向新手的完整教程
  • I2C总线多主模式下的起始信号竞争分析
  • 终极音乐歌词神器:网易云QQ音乐歌词一键获取全攻略
  • Python金融数据分析实战:从数据获取到策略回测的完整指南
  • 10分钟精通OpenCode完整安装攻略:从新手到专家的配置指南