繁体   English   中英

Nuxt3 Vite 服务器端口

[英]Nuxt3 Vite server port

我需要为 Nuxt3 配置服务器端口。 我尝试这样做:

nuxt.config.ts

import { defineNuxtConfig } from 'nuxt3'

export default defineNuxtConfig(
  vite: {
    server: {
      port: 5000,
    },
  },
})

但它不起作用。 Nuxt3如何设置服务器端口?

如此处所述,目前不支持此功能。

改成这样

{
  "scripts": {
    "build": "nuxt build",
    "dev": "nuxt dev --port=5678", // here
    "generate": "nuxt generate",
    "preview": "nuxt preview"
  },
  "devDependencies": {
    "nuxt": "3.0.0-rc.1"
  }
}

以下是如何更改生产端口: https ://github.com/nuxt/framework/discussions/1884#discussioncomment-1631668

我在所有平台(Windows、Linux、MacOS)中devproduction模式的解决方案:

  1. 安装cross-env以支持跨平台。
sudo npm i cross-env -g
  1. 编辑您的项目package.json
{
  "private": true,
  "scripts": {
    "build": "nuxt build",
    "dev": "nuxt dev --port=8001",
    "generate": "nuxt generate",
    "preview": "cross-env PORT=8001 node .output/server/index.mjs"
  },
  "devDependencies": {
    "nuxt": "3.0.0-rc.4"
  },
}

  1. 运行应用程序
yarn run preview
module.exports = {
  apps: [
    {
      name: 'NuxtApp',
      port: 3001,
      exec_mode: 'cluster',
      instances: '1',
      script: './.output/server/index.mjs',
      args: 'preview',
    },
  ],
}

你可以在你的 ecosystem.config.js 中这样使用

如果您使用的是 PM2,请在生态系统.config.js 上设置端口

module.exports = {
  apps: [
    {
      name: 'NuxtAppName',
      exec_mode: 'cluster',
      instances: 'max',
      script: './.output/server/index.mjs',
    port: 5000
    }
  ]
}

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM