news 2026/4/21 3:44:33

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

作者头像

张小明

前端开发工程师

1.2k 24
文章封面图
【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).
版权声明: 本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如若内容造成侵权/违法违规/事实不符,请联系邮箱:809451989@qq.com进行投诉反馈,一经查实,立即删除!
网站建设 2026/4/18 1:34:15

OpenMV在智能农业中的应用:新手教程(零基础入门)

从零开始玩转农业视觉&#xff1a;用 OpenMV 给农田装上“眼睛” 你有没有想过&#xff0c;一块巴掌大的小板子&#xff0c;能看懂庄稼长势、认出杂草、甚至判断番茄熟没熟&#xff1f;听起来像科幻片&#xff1f;其实这在今天已经不是梦。而且&#xff0c;哪怕你是编程小白&am…

作者头像 李华
网站建设 2026/4/17 18:46:30

CVAT团队协作实战指南:7个高效标注技巧提升项目交付速度

CVAT团队协作实战指南&#xff1a;7个高效标注技巧提升项目交付速度 【免费下载链接】cvat Annotate better with CVAT, the industry-leading data engine for machine learning. Used and trusted by teams at any scale, for data of any scale. 项目地址: https://gitcod…

作者头像 李华
网站建设 2026/4/17 22:23:04

Supertonic轻量化设计:66M参数背后的工程智慧

Supertonic轻量化设计&#xff1a;66M参数背后的工程智慧 1. 引言&#xff1a;设备端TTS的性能革命 随着边缘计算和本地AI推理需求的增长&#xff0c;文本转语音&#xff08;Text-to-Speech, TTS&#xff09;系统正从云端向设备端迁移。用户对低延迟、高隐私性和离线可用性的…

作者头像 李华
网站建设 2026/4/17 21:50:47

终极游戏控制器模拟指南:轻松配置ViGEmBus驱动

终极游戏控制器模拟指南&#xff1a;轻松配置ViGEmBus驱动 【免费下载链接】ViGEmBus 项目地址: https://gitcode.com/gh_mirrors/vig/ViGEmBus 还在为游戏控制器兼容性烦恼吗&#xff1f;&#x1f914; ViGEmBus驱动能够完美解决这一问题&#xff01;这是一款专业的Wi…

作者头像 李华
网站建设 2026/4/18 12:07:35

Mac硬件升级深度指南:突破系统限制的工程级解决方案

Mac硬件升级深度指南&#xff1a;突破系统限制的工程级解决方案 【免费下载链接】OpenCore-Legacy-Patcher 体验与之前一样的macOS 项目地址: https://gitcode.com/GitHub_Trending/op/OpenCore-Legacy-Patcher 问题诊断&#xff1a;硬件兼容性评估 在考虑升级老旧Mac之…

作者头像 李华
网站建设 2026/4/19 1:32:55

超实用!XUnity自动翻译插件完整安装与配置指南

超实用&#xff01;XUnity自动翻译插件完整安装与配置指南 【免费下载链接】XUnity.AutoTranslator 项目地址: https://gitcode.com/gh_mirrors/xu/XUnity.AutoTranslator 还在为外语游戏中的语言障碍而烦恼吗&#xff1f;XUnity AutoTranslator是一款专为Unity游戏设计…

作者头像 李华