news 2026/5/4 23:43:45

【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/1 14:35:02

GLM-ASR-Nano-2512车载系统:车内语音交互实现指南

GLM-ASR-Nano-2512车载系统&#xff1a;车内语音交互实现指南 1. 引言 随着智能座舱技术的快速发展&#xff0c;车内语音交互已成为提升驾驶体验的核心功能之一。用户期望在复杂行车环境中&#xff0c;依然能够通过自然语言与车辆进行高效沟通。然而&#xff0c;现实场景中的…

作者头像 李华
网站建设 2026/5/3 6:54:25

PDF-Extract-Kit黑科技:6GB显存也能跑大文档的秘诀

PDF-Extract-Kit黑科技&#xff1a;6GB显存也能跑大文档的秘诀 你是不是也遇到过这样的尴尬&#xff1f;手头有一堆PDF年度报告、项目总结、财务审计文件要处理&#xff0c;但电脑配置一般&#xff0c;尤其是显卡——还是别人淘汰下来的二手8GB显卡。作为NGO组织的IT志愿者&am…

作者头像 李华
网站建设 2026/4/30 13:00:55

Qwen3-4B-Instruct-2507镜像部署:Chainlit前端配置详细步骤

Qwen3-4B-Instruct-2507镜像部署&#xff1a;Chainlit前端配置详细步骤 1. 背景与目标 随着大模型在实际应用中的不断深入&#xff0c;高效、易用的本地化部署方案成为开发者关注的重点。Qwen3-4B-Instruct-2507作为通义千问系列中性能优异的40亿参数指令模型&#xff0c;在通…

作者头像 李华
网站建设 2026/5/1 11:30:03

终极指南:10个smartmontools 7.5磁盘监控实用技巧

终极指南&#xff1a;10个smartmontools 7.5磁盘监控实用技巧 【免费下载链接】smartmontools Official read only mirror of the smartmontools project SVN 项目地址: https://gitcode.com/gh_mirrors/smar/smartmontools smartmontools是一款强大的开源磁盘健康监控工…

作者头像 李华
网站建设 2026/5/1 7:08:26

BabelDOC:智能PDF翻译工具的完整使用指南

BabelDOC&#xff1a;智能PDF翻译工具的完整使用指南 【免费下载链接】BabelDOC Yet Another Document Translator 项目地址: https://gitcode.com/GitHub_Trending/ba/BabelDOC 还在为阅读外文PDF文档而烦恼吗&#xff1f;BabelDOC作为一款专业的PDF文档智能翻译工具&a…

作者头像 李华
网站建设 2026/5/1 9:22:24

下一代文本嵌入实战:Qwen3-0.6B开源模型部署完整指南

下一代文本嵌入实战&#xff1a;Qwen3-0.6B开源模型部署完整指南 1. 背景与目标 随着大语言模型在检索增强生成&#xff08;RAG&#xff09;、语义搜索和多模态理解等场景中的广泛应用&#xff0c;高质量的文本嵌入模型成为构建智能系统的核心组件。传统的通用语言模型虽具备…

作者头像 李华