-
-
Notifications
You must be signed in to change notification settings - Fork 2.6k
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 relative base (linking of assets and base) / vite embeded deployment #3360
Comments
Related to #2561, assigning to @tony-navillus to tackle soon. |
Interesting! I thought that we already supported this, and that this was existing behavior. Looks like we may be mixing relative and absolute based on the use-case. |
Muhymin tried to override base config, but Astro still set an absolute base: import { defineConfig } from "astro/config";
// https://astro.build/config
export default defineConfig({
base: "./",
experimental: {
integrations: true,
},
integrations: [
{
name: "path-denormalizer",
hooks: {
"astro:config:setup": function ({ config, updateConfig }) {
console.log(config.base);
return updateConfig({ base: "./" });
},
"astro:config:done": function ({ config }) {
console.log(config.base);
},
},
},
],
}); Muhymins comment:
If there is anything I can help with (apart from writing js, because I'm currently missing the time to learn that), I'll gladly do so, I really hope this is fixable without a breaking change. Especially when looking at the planed v1 release. |
Looks like there's a very recent Vite PR that adds better support for this! We'll be able to add this support properly once Vite 3.0 is released and pulled into Astro :party: |
vite 3.0 has finally landed: https://github.com/vitejs/vite#packages |
I'm using version 1.0 and I still can't get the relative path with the "base: './'" in the settings. Any alternative to make this work? |
@andresantiagohellmann I think you can use import.meta.env.BASE_URL |
Closing in favor of #4229 |
What version of
astro
are you using?v1.0.0-beta.28
Are you using an SSR adapter? If so, which one?
None
What package manager are you using?
npm
What operating system are you using?
Linux, Windows
Describe the Bug
I need my site to be able to deploy with out predefined root/path.
To be able to deploy the site like that I would need astro/vite to generate paths for links/styles/js relative and not absolute like it currently is.
The reason for me to want to deploy the site with relative paths is convenience, but also in Gitlab Pages (and probably Github and other forges) the site is accessible from two URLs at the same time:
The only way to support this, is to have relative paths.
what I did
If I set the base to an empty string, the site should be generated for "embedded deployment" => relative paths.
This is also described in the official documentation of vite: https://vitejs.dev/config/#base
the configuration used in the two examples below for
vite.config.js
andastro.config.mjs
want
This works with out a problem in the build output
npm run build
of a site created withnpm init vite
and the config from above invite.config.js
:<link rel="stylesheet" href="assets/index.cf80e917.css">
<a href="posts">Read more</a>
working example (vite svelte): https://stackblitz.com/edit/vitejs-vite-4elyud?file=vite.config.js
have
If I create the site with
npm create astro@latest
the build output has absolute paths when using the config from above inastro.config.mjs
:<link rel="stylesheet" href="/assets/asset.c871d887.css"></link>
<a href="/posts" class="astro-QAKS6ZHX">Read more</a>
working example (astro with vite): https://stackblitz.com/edit/github-99rdyj-an7xgv?file=astro.config.mjs
past conversations
Link to Minimal Reproducible Example
https://stackblitz.com/edit/github-99rdyj-an7xgv?file=astro.config.mjs
Participation
If I missed anything please let me know.
The text was updated successfully, but these errors were encountered: