gh 页面上的 SvelteKit 部署不起作用。仅显示 HTML,不加载 CSS 和 JS

问题描述 投票:0回答:1

如果我在本地构建项目并查看预览,一切正常。如果我将它部署到 gh-pages,则只显示 HTML 并且无法加载 JS 和 CSS。这是为什么?我没有发现我做错了什么,我也在官方的 svelte discord 服务器上问过。

我用过的:
框架:SvelteKit
适配器:@sveltejs/adapter-static
托管服务:GitHub => gh-pages

部署操作:https://github.com/marketplace/actions/deploy-to-github-pages
构建文件都在一个发布到 gh-pages 的分支中。

=> 结果:
gh页面站点:https://jonasfroeller.github.io/jonasfroeller/de
回购:https://github.com/jonasfroeller/jonasfroeller/tree/master/portfolio

"dependencies": {
    "@tailwindcss/typography": "^0.5.9",
    "daisyui": "^2.46.1",
    "iconify-icon": "^1.0.2",
    "typesafe-i18n": "^5.18.1"
}

svelte.config.js > paths.base: process.env.NODE_ENV === 'production' ? '/jonasfroeller' : ''

可能很重要:整个网站都在一个名为 [lang] 的动态路由中。如果您不指定语言,您将被拒绝。

控制台中的错误示例:GET https://jonasfroeller.github.io/jonasfroeller/\\_app/immutable/chunks/i18n-svelte-76a2aa52.js net::ERR_ABORTED 404

我尝试了其他 2 个动作,但结果相似。我还尝试将 .nojekyll 文件添加到构建文件夹,因为 jekyll 不喜欢“_,.,#,~”,但效果不佳。 (https://stackoverflow.com/questions/40333629/cant-load-existing-js-file-on-gh-pages)

deployment github-actions http-status-code-404 github-pages sveltekit
1个回答
1
投票

有专门的文档

有两种选择:

  • 只需在 .nojekyll
  • 中放置一个 static 文件即可禁用 Jekyll
  • 通过 Svelte 配置中的 _app_ 目录的名称更改为不以 kit.appDir 开头的名称。
© www.soinside.com 2019 - 2024. All rights reserved.