news 2026/4/16 14:08:50

【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/16 9:02:03

小桔调研问卷系统终极指南:打造专属数据收集完整解决方案

小桔调研问卷系统终极指南&#xff1a;打造专属数据收集完整解决方案 【免费下载链接】xiaoju-survey 「快速」打造「专属」问卷系统, 让调研「更轻松」 项目地址: https://gitcode.com/GitHub_Trending/xia/xiaoju-survey 还在为数据收集效率低下而烦恼吗&#xff1f;想…

作者头像 李华
网站建设 2026/4/16 9:04:03

通义千问2.5-7B-Instruct农业应用:种植建议生成

通义千问2.5-7B-Instruct农业应用&#xff1a;种植建议生成 1. 技术背景与应用场景 随着人工智能在农业领域的深入渗透&#xff0c;智能决策支持系统正逐步成为现代化精准农业的核心组成部分。传统农业依赖经验判断&#xff0c;在气候多变、资源紧张的背景下已显现出局限性。…

作者头像 李华
网站建设 2026/4/16 12:15:44

Qwen2.5-0.5B低成本部署:中小企业AI落地实战

Qwen2.5-0.5B低成本部署&#xff1a;中小企业AI落地实战 1. 引言&#xff1a;为何选择Qwen2.5-0.5B-Instruct进行轻量级AI部署&#xff1f; 随着大语言模型&#xff08;LLM&#xff09;技术的快速发展&#xff0c;越来越多企业希望将AI能力集成到自身业务系统中。然而&#xf…

作者头像 李华
网站建设 2026/4/16 5:41:43

AO3镜像站完全攻略:轻松突破访问壁垒的终极方案

AO3镜像站完全攻略&#xff1a;轻松突破访问壁垒的终极方案 【免费下载链接】AO3-Mirror-Site 项目地址: https://gitcode.com/gh_mirrors/ao/AO3-Mirror-Site 还在为无法访问AO3而苦恼吗&#xff1f;&#x1f914; 作为全球最大的同人作品平台&#xff0c;AO3汇集了数…

作者头像 李华
网站建设 2026/4/16 7:21:46

HY-MT1.5-1.8B术语干预功能实战应用

HY-MT1.5-1.8B术语干预功能实战应用 1. 引言&#xff1a;轻量级翻译模型的工程突破 随着多语言内容在移动互联网、跨境电商和本地化服务中的广泛应用&#xff0c;对高效、精准且可部署于终端设备的神经翻译模型需求日益增长。传统大模型虽具备较强的语言理解能力&#xff0c;…

作者头像 李华
网站建设 2026/4/16 7:29:26

系统提示词可改?--system参数自定义方法揭秘

系统提示词可改&#xff1f;--system参数自定义方法揭秘 在大模型微调实践中&#xff0c;如何让模型“认识自己”并具备特定身份属性&#xff0c;是提升交互体验的关键一步。本文将围绕 Qwen2.5-7B-Instruct 模型&#xff0c;结合预置的 ms-swift 微调框架&#xff0c;深入解析…

作者头像 李华