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
Allow for relative paths of assets when building for static deployments #9569
Comments
It is possible to use sveltekit outside of the domain root, all you need is define the base path in the const config = {
preprocess: vitePreprocess(),
kit: {
adapter: adapter(),
paths: {
base: '/canada/markting/'
},
},
}; |
Or even better like this: ...
paths: {
base: process.env.PUBLIC_BASE_PATH,
},
... |
This doesn't allow for a relative path, the path needs to be specified everytime there is a new build in a new environment. A relative base path option would be really appreciated, this can be done in the Vite config by setting the |
This is kind of the issue we have, too. More precisely, when we |
Here is a basic reproduction of the issue: After starting the environment, run Expected:Image URL does not start with absolute slash ActualImage URL contains absolute |
I got around this issue by running a small script (replaceAssets.js) after the build process: replaceAssets.js
svelte.config.js
This tricks SvelteKit to build (as the assets path is absolute), and the script replaces all instances of "http://REPLACEME" with ".", such that the paths are relative. I've added this script to the build process, so my build script now looks like this: package.json
(To read all files recursively I found a snippet from "https://stackoverflow.com/questions/5827612/node-js-fs-readdir-recursive-directory-search") |
All of the below not work,it is sad. |
This comment was marked as spam.
This comment was marked as spam.
This comment was marked as spam.
This comment was marked as spam.
This comment was marked as spam.
This comment was marked as spam.
I'll bump this, as far as I'm concerned, absolute asset paths don't work at all when trying to build a tizen app, which is why I think this would be crucial if sveltekit is to be used for tv app development. |
We have lots of instances of our app running on the same host, so this problem is important for us. What we're doing to work around this problem is setting
let base = ''
if (process.env.PLAYWRIGHT_TEST_BASE_URL) base = process.env.TEST_BASE_PATH
else if (process.env.NODE_ENV === 'production') base = '/%base%'
const config = {
kit: { paths: { base }}
} It has a problem with Would be great to have possibility to use relative paths. |
This is also an issue for us. In production, we want to mount the assets directory and use nginx to proxy those static assets while our Django app is responsible for catching all proper URLs to be routed to index.html. We can then seamlessly put our CDN in front and swap URLs as necessary without rebuilding. It also ensures our dev and production environments are more easily aligned. This would be easily enabled with adding relative paths to the assets URL so asset hosting routing can be independent of the base path of index.html. If I've missed an easy way to achieve this, please do let me know. Thanks so much for the help! Also linking this related request: |
Describe the problem
I'm developing a Kit app that, when deployed, will have a few directories above it, e.g., in
dev
a route might look like:http://localhost/about
But in production, after rendering to static and deploying “somewhereoutthere”, the same route will be:
https://wwwcompanycom/canada/markting/about
The problem is—and maybe there’s an option for this that I'm missing—is that the static JS and CSS assets assume a route path:
Describe the proposed solution
Allow for an option in
svelte.config.js
to allow for relative asset paths so that we can get:(See the ./ ?)
Alternatives considered
No response
Importance
i cannot use SvelteKit without it
Additional Information
No response
The text was updated successfully, but these errors were encountered: