[英]Nuxt3 Vite server port
I need to config server port for Nuxt3.我需要为 Nuxt3 配置服务器端口。 I try to do it so:我尝试这样做:
nuxt.config.ts
import { defineNuxtConfig } from 'nuxt3'
export default defineNuxtConfig(
vite: {
server: {
port: 5000,
},
},
})
But it doesn't work.但它不起作用。 How to set server port in Nuxt3? Nuxt3如何设置服务器端口?
As told here , this is currently not supported.如此处所述,目前不支持此功能。
Change it like this改成这样
{
"scripts": {
"build": "nuxt build",
"dev": "nuxt dev --port=5678", // here
"generate": "nuxt generate",
"preview": "nuxt preview"
},
"devDependencies": {
"nuxt": "3.0.0-rc.1"
}
}
Here is how to change the port for production: https://github.com/nuxt/framework/discussions/1884#discussioncomment-1631668以下是如何更改生产端口: https ://github.com/nuxt/framework/discussions/1884#discussioncomment-1631668
My solution for dev
and production
mode in all platforms (windows, Linux, MacOS) :我在所有平台(Windows、Linux、MacOS)中dev
和production
模式的解决方案:
cross-env
to support cross platforms.安装cross-env
以支持跨平台。sudo npm i cross-env -g
package.json
编辑您的项目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"
},
}
yarn run preview
module.exports = {
apps: [
{
name: 'NuxtApp',
port: 3001,
exec_mode: 'cluster',
instances: '1',
script: './.output/server/index.mjs',
args: 'preview',
},
],
}
You can use like this in your ecosystem.config.js你可以在你的 ecosystem.config.js 中这样使用
If you are using PM2, set the port on 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.