news 2026/2/4 1:20:32

【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/1/28 7:18:35

终极指南:如何用HsMod插件彻底改变你的炉石传说体验

终极指南&#xff1a;如何用HsMod插件彻底改变你的炉石传说体验 【免费下载链接】HsMod Hearthstone Modify Based on BepInEx 项目地址: https://gitcode.com/GitHub_Trending/hs/HsMod 想要让炉石传说游戏运行更加流畅吗&#xff1f;HsMod插件正是你需要的游戏优化利器…

作者头像 李华
网站建设 2026/1/26 17:42:18

OpenCore Legacy Patcher:三步让老款Mac焕然一新的终极指南

OpenCore Legacy Patcher&#xff1a;三步让老款Mac焕然一新的终极指南 【免费下载链接】OpenCore-Legacy-Patcher 体验与之前一样的macOS 项目地址: https://gitcode.com/GitHub_Trending/op/OpenCore-Legacy-Patcher 还在为苹果官方"抛弃"的老款Mac无法升级…

作者头像 李华
网站建设 2026/2/1 9:40:09

告别繁琐PS操作|CV-UNet大模型镜像实现自动化抠图

告别繁琐PS操作&#xff5c;CV-UNet大模型镜像实现自动化抠图 1. 引言&#xff1a;图像抠图的痛点与技术演进 在数字内容创作、电商产品展示、影视后期等场景中&#xff0c;图像抠图是一项高频且关键的任务。传统依赖Photoshop等专业工具的手动操作不仅耗时耗力&#xff0c;还…

作者头像 李华
网站建设 2026/1/30 2:39:40

Edge TTS终极指南:跨平台语音合成的完整解决方案

Edge TTS终极指南&#xff1a;跨平台语音合成的完整解决方案 【免费下载链接】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/edge-…

作者头像 李华
网站建设 2026/1/27 21:11:13

YOLOv8多线程优化:并发请求处理能力提升教程

YOLOv8多线程优化&#xff1a;并发请求处理能力提升教程 1. 引言 1.1 业务场景描述 在工业级目标检测应用中&#xff0c;YOLOv8凭借其高精度与低延迟的特性&#xff0c;已成为实时视觉分析的核心技术。然而&#xff0c;在实际部署过程中&#xff0c;单线程处理模式往往成为系…

作者头像 李华
网站建设 2026/2/3 15:38:14

Qwen3-VL-2B视觉理解机器人技术:跨模态对齐研究

Qwen3-VL-2B视觉理解机器人技术&#xff1a;跨模态对齐研究 1. 引言&#xff1a;多模态AI时代的视觉理解需求 随着人工智能从单一文本模态向图文、音视频等多模态方向演进&#xff0c;具备“看懂世界”能力的视觉语言模型&#xff08;Vision-Language Model, VLM&#xff09;…

作者头像 李华