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.


  • 2020-02-20 18:35:21

    Vue加载组件、动态加载组件的几种方式

    组件是Vue.js最强大的功能之一。组件可以扩展HTML元素,封装可重用的代码。在较高层面上,组件是自定义的元素,Vue.js的编译器为它添加特殊功能。在有些情况下,组件也可以是原生HTML元素的形式,以is特性扩展。

  • 2020-02-22 13:58:50

    深入理解 requestAnimationFrame

    在Web应用中,实现动画效果的方法比较多,Javascript 中可以通过定时器 setTimeout 来实现,css3 可以使用 transition 和 animation 来实现,html5 中的 canvas 也可以实现。除此之外,html5 还提供一个专门用于请求动画的API,那就是 requestAnimationFrame,顾名思义就是请求动画帧。 为了深入理解 requestAnimationFrame 背后的原理,我们首先需要了解一下与之相关的几个概念:

  • 2020-02-22 17:35:14

    使用tweenjs写一个发牌的demo

    移动端h5的三大抽奖方式:转盘,老虎机,翻纸牌。 前两样demo比较多,用户也审美疲劳了。这次微信公众号要抽奖,于是调研了下翻纸牌。

  • 2020-02-22 17:45:43

    tweenjs简单快速学习

    tweenjs 是使用 JavaScript 中的一个简单的补间动画库,支持数字、对象的属性和 CSS 样式属性的赋值。 tweenjs 以平滑的方式修改元素的属性值,需要传递给 tween 要修改的值、动画结束时的最终值和动画花费时间(duration),之后 tween 引擎就可以计算从开始动画点到结束动画点之间值,从而产生平滑的动画效果。

  • 2020-02-22 17:47:12

    easeJs入门学习教程

    createjs中包含以下四个部分: EaselJS:用于 Sprites、动画、向量和位图的绘制,创建 HTML5 Canvas 上的交互体验(包含多点触控) TweenJS:用于做动画效果 SoundJS:音频播放引擎 PreloadJS:网站资源预加载