How to set basePath to relative ?

Hi, I'm looking for a way to change the /_nuxt/ path in my static build to ./_nuxt/ I found this in the docs: https://nuxt.com/docs/api/nuxt-config#baseurl, but when I change it to './', it gets rewritten in the build to '/'.
3 Replies
kapa.ai
kapa.ai2mo ago
Hi @Nathan / npldev. I'm kapa.ai, your friendly support bot. I will try to answer your question by searching through the knowledge base. :wave: ---------------------- To set the base path to a relative path in Nuxt, you need to configure the app.baseURL option in your nuxt.config.ts file. However, you're correct that simply setting it to './' might not work as expected in all cases. Based on the knowledge sources provided, here's how you can approach this: 1. First, set the app.baseURL in your nuxt.config.ts:
export default defineNuxtConfig({
app: {
baseURL: './'
}
})
export default defineNuxtConfig({
app: {
baseURL: './'
}
})
2. However, as you've noticed, this might get rewritten to '/' during the build process. To prevent this, you need to set it at runtime. You can do this by using an environment variable:
export default defineNuxtConfig({
app: {
baseURL: process.env.NUXT_APP_BASE_URL || '/'
}
})
export default defineNuxtConfig({
app: {
baseURL: process.env.NUXT_APP_BASE_URL || '/'
}
})
3. Then, when running your application, set the environment variable:
NUXT_APP_BASE_URL=./ node .output/server/index.mjs
NUXT_APP_BASE_URL=./ node .output/server/index.mjs
This approach is mentioned in the Nuxt Configuration documentation. It's important to note that changing the base URL can affect how assets and routes are resolved, especially in more complex setups or when deploying to certain environments. If you're specifically trying to change the /_nuxt/ path in your build output, you might also want to look into the app.buildAssetsDir configuration option, which allows you to customize the folder name for built site assets. However, the documentation doesn't provide a clear way to set this to a relative path. If you're still experiencing issues after trying these approaches, it might be worth checking if there are any specific considerations for your deployment environment or build setup that could be affecting the base URL resolution. Nuxt Configuration documentation ---------------------- Note: you can ask me a follow up question by @ mentioning me again :speech_balloon: ----------------------
kapa.ai
kapa.ai2mo ago
<@369575985567498242> Kapa.ai is still learning and improving, please let me know how I did by reacting below.
Nathan / npldev
Nathan / npldevOP5w ago
hello, does anyone have an idea ?

Did you find this page helpful?