-
-
Notifications
You must be signed in to change notification settings - Fork 2k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
use relative asset paths #4250
use relative asset paths #4250
Conversation
🦋 Changeset detectedLatest commit: 90193bd The changes in this PR will be included in the next version bump. This PR includes changesets to release 1 package
Not sure what this means? Click here to learn what changesets are. Click here if you're a maintainer who wants to add another changeset to this PR |
I've kept this up to date with https://github.com/jy0529/vite-plugin-dynamic-publicpath is out now. Maybe use it to resolve dynamic import? |
I was able to track it down to const a = "modulepreload",
o = {},
u = "/_app/",
h = function (s, n) {
return !n || n.length === 0
? s()
: Promise.all(
n.map((e) => {
if (((e = `${u}${e}`), e in o)) return
o[e] = !0
const t = e.endsWith(".css"),
i = t ? '[rel="stylesheet"]' : ""
if (document.querySelector(`link[href="${e}"]${i}`)) return
const r = document.createElement("link")
if (
((r.rel = t ? "stylesheet" : a),
t || ((r.as = "script"), (r.crossOrigin = "")),
(r.href = e),
document.head.appendChild(r),
t)
)
return new Promise((l, c) => {
r.addEventListener("load", l),
r.addEventListener("error", () =>
c(new Error(`Unable to preload CSS for ${e}`))
)
})
})
).then(() => s())
}
export { h as _ } Note that "/_app/" was here. If there is a way to change the way This was mentioned in vitejs/vite#2024. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is there anything special we need to do for https://kit.svelte.dev/docs/modules#$app-paths-assets?
Assuming not, this looks good to me
I don't think so. This PR still uses an absolute base in SSR mode, as I couldn't figure out an elegant way to use |
Is there an option to keep absolute paths when using static adapter? |
This was just a quick experiment inspired by #3014 to see if it's possible to create prerendered SvelteKit apps that don't even need a webserver.
It basically works — if you have routes like
src/routes/index.html.svelte
instead ofindex.svelte
, you can double-click on the resultingbuild/index.html
file, and you have an (almost) fully working site, because the generated CSS and JS are loaded fromfile://
URLs. Might be useful in certain contexts, and is a step towards #595.One thing it doesn't account for is fallback routes (i.e. if you visit
/foo/bar/baz
in an SPA and it's served by the fallback page, the relative URLs will be wrong). The biggest issue though is that Vite uses absolute URLs — if you import an asset from JS or CSS, it will be imported from an absolute URL rather than a relative one. I think that could be changed (along with vitejs/vite#2009) for the benefit of all, as it would make every Vite app more portable. Unless and until that happens, I'm going to mark this as draft and not spend any more time on it.Please don't delete this checklist! Before submitting the PR, please make sure you do the following:
Tests
pnpm test
and lint the project withpnpm lint
andpnpm check
Changesets
pnpx changeset
and following the prompts. All changesets should bepatch
until SvelteKit 1.0