英文:
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
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论