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-11-07 08:47:00

    详解vue2.6插槽更新v-slot用法总结

    在 2.6.0 中,我们为具名插槽和作用域插槽引入了一个新的统一的语法 (即 v-slot 指令)。这篇文章主要介绍了详解vue2.6插槽更新v-slot用法总结,具有一定的参考价值,感兴趣的小伙伴们可以参考一下

  • 2019-11-08 09:34:46

    CSS3 Transition详解和使用

    Transition 可以设置 CSS 属性的过渡效果,它有以下几个属性。 transition-property 用于指定应用过渡属性的名称 transition-duration 用于指定这个过渡的持续时间 transition-delay 用于指定延迟过渡的时间 transition-timing-function 用于指定过渡的类型 transition-property transition-property 用于指定应用过渡的属性名称,可以指定多个属性名称,多个属性名称之间用, 分隔。 默认值为 all 也就是所有的元素都应用过渡效果。 例如,想让容器的宽高有一个过渡的效果,就可以这样写:

  • 2019-11-09 19:16:35

    java标记过期方法

    java注解:@Deprecated(不建议使用的,废弃的);@SuppressWarnings(忽略警告,达到抑制编译器产生警告的目的)

  • 2019-11-12 02:56:39

    使用.htaccess重定向后无法显示图片,CSS失效,该如何处理

    现在我需要把这个域名泛解析到blog目录(*.mydomain.org),同时保持另外两个目录的解析不变。尝试对最后一段作以下修改后(前面的内容不变),出现问题:另两个目录中的网站内的图片无法显示,CSS全部失效。