news 2026/8/9 18:42:35

【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/7/31 1:25:40

NVIDIA Profile Inspector终极使用指南:释放显卡隐藏性能的完整教程

NVIDIA Profile Inspector终极使用指南&#xff1a;释放显卡隐藏性能的完整教程 【免费下载链接】nvidiaProfileInspector 项目地址: https://gitcode.com/gh_mirrors/nv/nvidiaProfileInspector 还在为高端显卡在某些游戏中表现不佳而烦恼吗&#xff1f;想要获得比官方…

作者头像 李华
网站建设 2026/8/1 18:25:13

LeaguePrank技术深度解析:英雄联盟客户端的个性化革命

LeaguePrank技术深度解析&#xff1a;英雄联盟客户端的个性化革命 【免费下载链接】LeaguePrank 项目地址: https://gitcode.com/gh_mirrors/le/LeaguePrank 在英雄联盟的游戏生态中&#xff0c;个人资料的展示效果往往受到官方功能的限制。LeaguePrank作为一款开源工具…

作者头像 李华
网站建设 2026/8/2 6:55:12

SAM3环境部署:CUDA12.6下的高效图像分割方案

SAM3环境部署&#xff1a;CUDA12.6下的高效图像分割方案 1. 技术背景与核心价值 随着视觉理解任务的不断演进&#xff0c;通用图像分割模型正逐步从“框选引导”向“语义驱动”转变。传统的交互式分割方法依赖用户手动标注点、框或涂鸦作为输入提示&#xff0c;操作门槛高且效…

作者头像 李华
网站建设 2026/7/30 20:38:51

百度网盘下载限速终结者:3步获取高速直连地址

百度网盘下载限速终结者&#xff1a;3步获取高速直连地址 【免费下载链接】baidu-wangpan-parse 获取百度网盘分享文件的下载地址 项目地址: https://gitcode.com/gh_mirrors/ba/baidu-wangpan-parse 你是否曾经面对百度网盘那令人绝望的下载速度束手无策&#xff1f;几…

作者头像 李华
网站建设 2026/7/31 5:57:48

XUnity Auto Translator:打破语言壁垒的Unity游戏智能翻译方案

XUnity Auto Translator&#xff1a;打破语言壁垒的Unity游戏智能翻译方案 【免费下载链接】XUnity.AutoTranslator 项目地址: https://gitcode.com/gh_mirrors/xu/XUnity.AutoTranslator 还在为外语游戏中的生涩文本而困扰吗&#xff1f;想要快速为Unity项目添加多语言…

作者头像 李华
网站建设 2026/8/7 7:33:29

零基础玩转AI对话:Qwen2.5-0.5B保姆级入门教程

零基础玩转AI对话&#xff1a;Qwen2.5-0.5B保姆级入门教程 1. 教程简介与学习目标 随着大模型技术的普及&#xff0c;越来越多开发者希望在本地或边缘设备上部署轻量级AI对话系统。本教程面向零基础用户&#xff0c;手把手带你使用 Qwen/Qwen2.5-0.5B-Instruct 模型镜像&…

作者头像 李华