SvelteKit 部署在 gh-pages 上不起作用。只显示 HTML,CSS 和 JS 不加载。

huangapple go评论62阅读模式
英文:

SvelteKit deployment on gh - pages doesn't work. Only HTML is shown, CSS and JS doesn't load

问题

If I build the project locally and view the preview, everything works fine. If I deploy it to gh-pages only HTML is shown and JS & CSS cannot be loaded. Why is that? I don't find what I am doing wrong, i asked on the official svelte discord server too.

What I used:
Framework: SvelteKit
Adapter: @sveltejs/adapter-static
Hosting Service: GitHub => gh-pages

Deploy Action: https://github.com/marketplace/actions/deploy-to-github-pages
The build files are all in one branch that gets published to gh-pages.

=> Result:
gh-pages-site: https://jonasfroeller.github.io/jonasfroeller/de
repo: 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' : ''

may be important: The whole website is inside of a dynamic route called [lang]. If you don't specify a lang you are being forwarded.

Error example in the console: GET https://jonasfroeller.github.io/jonasfroeller/_app/immutable/chunks/i18n-svelte-76a2aa52.js net::ERR_ABORTED 404

I tried 2 other actions but they resulted similar. I also tried adding a .nojekyll file to the build folder because Jekyll doesn't like "_,.,#,~", that didn't work as well. (https://stackoverflow.com/questions/40333629/cant-load-existing-js-file-on-gh-pages)

英文:

If I build the project locally and view the preview, everything works fine. If I deploy it to gh-pages only HTML is shown and JS & CSS cannot be loaded. Why is that? I don't find what I am doing wrong, i asked on the official svelte discord server too.

What I used:
Framework: SvelteKit
Adapter: @sveltejs/adapter-static
Hosting Service: GitHub => gh-pages

Deploy Action: https://github.com/marketplace/actions/deploy-to-github-pages
The build files are all in one branch that gets published to gh-pages.

=> Result:
gh-pages-site: https://jonasfroeller.github.io/jonasfroeller/de
repo: 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' : ''

may be important: The whole website is inside of a dynamic route called [lang]. If you don't specify a lang you are being forworded.

Error example in the console: GET https://jonasfroeller.github.io/jonasfroeller/\_app/immutable/chunks/i18n-svelte-76a2aa52.js net::ERR_ABORTED 404

I tried 2 other actions but they resulted simillar. I also tried adding a .nojekyll file to the build folder because jekyll doesn't like "_,.,#,~", that didn't work as well. (https://stackoverflow.com/questions/40333629/cant-load-existing-js-file-on-gh-pages)

答案1

得分: 1

有关此特定内容的文档1

static目录中放置.nojekyll文件来禁用Jekyll。

英文:

There is documentation on this specifically.

Disable Jekyll by simply placing a .nojekyll file in static

答案2

得分: 1

I understand that there is already an accepted answer, but the fix didn't help me. What worked for me was this.

Turns out that the problem is that in my svelte.config.js I had paths:
{ base: dev ? '' : '/my-portfolio', } because it was needed by GitHub
in order to make it work. Apparently now it doesn't need it anymore,
so all the 404 were right since it was trying to get non-existing
files.

https://github.com/orgs/community/discussions/52062

Try removing the paths that you might have configured in svelte.config.js.

英文:

I understand that there is already an accepted answer, but the fix didn't help me. What worked for me was this.

> Turns out that the problem is that in my svelte.config.js I had paths:
> { base: dev ? '' : '/my-portfolio', } because it was needed by GitHub
> in order to make it work. Apparently now it doesn't need it anymore,
> so all the 404 were right since it was trying to get non-existing
> files.

https://github.com/orgs/community/discussions/52062

Try removing the paths that you might have configured in svelte.config.js

huangapple
  • 本文由 发表于 2023年2月19日 07:35:16
  • 转载请务必保留本文链接:https://go.coder-hub.com/75497065.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定