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.


  • 2019-07-09 20:26:49

    使用Mysqldump命令备份和恢复Mysql数据库

    之前一直习惯用phpmyadmin备份恢复数据库,不过数据库文件大了用phpmyadmin就不行了。这时候我们就需要Mysqldump来备份和恢复。以下内容来自网络。

  • 2019-07-10 18:02:28

    Centos7安装percona-xtrabackup2.4和8.0版本

    Percona XtraBackup是一个基于MySQL的服务器的开源热备份实用程序 ,它不会在备份期间锁定您的数据库。 无论是24x7高负载服务器还是低事务量环境,Percona XtraBackup都旨在使备份成为一个无缝过程,而不会破坏生产环境中服务器的性能。

  • 2019-07-11 11:35:20

    VirtualBox添加新硬盘

    昨晚在自己的virtualbox中的linux装matlab2010a,没想到硬盘空间不足,所以找了下怎么添加硬盘的资料。也很简单,每几条命令。 大致流程:我的virtualbox版本是3.2.8,linux版本是xubuntu10.01吧貌似