nuxtjs一个项目部署多个网站

2023-09-19 16:45:29

下面有两个方案,各有利弊吧,其实也差不多 参考地址 Nuxt 3 multiple domains/projects

1. 方案一 :首页分目录

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:

  • Create a pages structure like this:

/pages
--/website1
--/website2
--/website3
  • Define an env variable like WEBSITE_ID (e.g. within your project's .env)

WEBSITE_ID="website1"
  • Inside of nuxt.config.ts add this configuration:

export default defineNuxtConfig({  //...
  dir: {    pages: `pages/${process.env.WEBSITE_ID}`
  },  //...})
  • When it's time to deploy your apps, inject the corresponding WEBSITE_ID env variable for each at build time.

  • While in development, simply edit the 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 /.


方案二: 利用nuxtjs3的新特性 layers,能更好的控制项目大小


f you're on Nuxt 3, you're probably after Layers here: https://nuxt.com/docs/getting-started/layers

A base app can be extended, thus sharing components etc with other apps.


  • 2018-01-04 15:16:05

    201712月如何买到阿里云免费SSL证书(0元SSL证书)

    2017年12月,阿里云搞了个安全月活动,安全活动有折扣。 但是,免费SSL证书却在此时进行过调整,调整后的操作中存在缺陷,不容易找到免费SSL证书。目前尚不清除这是bug还是刻意为之,阿里云作为国内云计算厂商第一,想必不会刻意为之。晚些时候我会提交阿里云聆听平台,反馈此问题,帮助大家后方便从阿里云购买免费SSL证书。

  • 2018-01-04 16:37:25

    怎么让自己的网站支持https 访问 - SLL证书服务

    让自己的网站能够通过 https://你的域名 进行访问。 实现这个需要给你服务器安装安全证书。安全证书是有偿的,你要去申请,当然如果你的服务器在阿里云,你可以向阿里云免费申请SSL证书(每个帐号最多申请20个)。

  • 2018-01-08 22:12:20

    加快gradle的编译速度总结-亲身经历

    这两题集成mob的maven,这个编译速度是慢的可怜啊,经过百度得出了这样一个方案,配置好以后那可是神速啊,妈妈再也不用担心我的编译速度看。嗷嗷的。

  • 2018-01-11 09:07:01

    微信小程序的组件用法与传统HTML5标签的区别

    小程序刚开放公测,互联网圈内开始了各种解读和猜测。其中有观点认为小程序和HTML5有着紧密关联,甚至小程序就是基于HTML5开发。 经过仔细研究文档和代码开发,从视图层的角度来说,小程序与传统HTML5还是有明显的区别,主要区别在于: