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.


  • 2021-01-10 17:19:00

    libc++_shared是什么冲突

    NDK 支持多种 C++ 运行时库。本文档介绍了这些库的相关信息、所涉及的折衷做法以及库的使用方法。

  • 2021-01-10 17:20:52

    NDK--CMakeLists配置第三方so库

    当我们创建一个NDK工程时,会自动创建一个CMakeLists.txt的文件,在AS中c++的编译器是使用LLVM,规则为cmake,今天来学习下cmake的基本套路 首先,我创建了两个NDK工程,第一个工程为lib,为第二个工程提供so库

  • 2021-01-12 10:56:09

    NodeJS封装mongodb

    NodeJS操作 Mongodb 并且对 Mongodb 类库进行封装