I am building a Nuxt 3 SSR application, which I'm getting rather familiar with. What I can't wrap my head around, if it's even possible, is to have a single Nuxt project for multiple domains. For example, I have a few websites such as websitea.com, websiteb.com, websitec.com, and want to keep pages separate, while sharing components, compostables, etc. I'm not sure if this is possible, but it would be greatly appreciated if anyone has any advice.
I had this requirement too and came up with this solution:
Everything is shared as one Nuxt 3 app with a single nuxt.config.ts. The only difference is that each app has it's own sub-directory within /pages.
Here's how I set it up:
/pages
--/website1
--/website2
--/website3
WEBSITE_ID (e.g. within your project's .env)WEBSITE_ID="website1"
nuxt.config.ts add this configuration:export default defineNuxtConfig({
//...
dir: {
pages: `pages/${process.env.WEBSITE_ID}`
},
//...
})
WEBSITE_ID env variable for each at build time.WEBSITE_ID within the .env to switch which website you're working on.This setup makes it so that for example, when website1 is active, pages/website1 is treated as the /pages directory... so pages/website1/index.vue would be resolved when requesting /.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With