news 2026/6/10 13:15:42

【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/5/23 6:54:51

如何快速实现Python文本转语音:Edge TTS实用技巧全解析

如何快速实现Python文本转语音&#xff1a;Edge TTS实用技巧全解析 【免费下载链接】edge-tts Use Microsoft Edges online text-to-speech service from Python WITHOUT needing Microsoft Edge or Windows or an API key 项目地址: https://gitcode.com/GitHub_Trending/ed…

作者头像 李华
网站建设 2026/6/10 13:08:24

XUnity Auto Translator:Unity游戏本地化的终极解决方案

XUnity Auto Translator&#xff1a;Unity游戏本地化的终极解决方案 【免费下载链接】XUnity.AutoTranslator 项目地址: https://gitcode.com/gh_mirrors/xu/XUnity.AutoTranslator XUnity Auto Translator是一款专为Unity游戏设计的智能翻译插件&#xff0c;能够自动识…

作者头像 李华
网站建设 2026/6/10 12:51:18

MinerU 2.5实战:历史文献PDF解析的特殊处理

MinerU 2.5实战&#xff1a;历史文献PDF解析的特殊处理 1. 引言 1.1 业务场景描述 在数字人文、古籍数字化和学术研究领域&#xff0c;历史文献的电子化是一项基础而关键的工作。这些文献通常以扫描版PDF形式存在&#xff0c;包含复杂的排版结构&#xff1a;多栏布局、手写体…

作者头像 李华
网站建设 2026/5/22 17:47:56

HY-MT1.5-1.8B媲美Gemini?质量分90%位对比实测

HY-MT1.5-1.8B媲美Gemini&#xff1f;质量分90%位对比实测 1. 引言&#xff1a;轻量级翻译模型的新标杆 随着多语言内容在全球范围内的快速传播&#xff0c;高质量、低延迟的神经机器翻译&#xff08;NMT&#xff09;需求日益增长。然而&#xff0c;传统大模型在移动端部署面…

作者头像 李华
网站建设 2026/6/10 11:19:55

ViGEmBus游戏控制器模拟驱动终极配置指南:从入门到精通

ViGEmBus游戏控制器模拟驱动终极配置指南&#xff1a;从入门到精通 【免费下载链接】ViGEmBus 项目地址: https://gitcode.com/gh_mirrors/vig/ViGEmBus ViGEmBus是一款专业的Windows内核级游戏控制器模拟驱动&#xff0c;能够完美模拟Xbox 360和DualShock 4等多种游戏…

作者头像 李华
网站建设 2026/5/29 18:35:17

Unity游戏多语言本地化终极指南:如何轻松实现自动翻译

Unity游戏多语言本地化终极指南&#xff1a;如何轻松实现自动翻译 【免费下载链接】XUnity.AutoTranslator 项目地址: https://gitcode.com/gh_mirrors/xu/XUnity.AutoTranslator 还在为外语游戏的语言障碍而烦恼吗&#xff1f;想要为你的Unity游戏快速添加多语言支持&…

作者头像 李华