1、配置package.json
“scripts”: {
“start”: “PORT=端口号 node .output/server/index.mjs”,
“build”: “nuxt build”,
“dev”: “nuxt dev --port 3001”,
“generate”: “nuxt generate”,
“preview”: “nuxt preview”,
“postinstall”: “nuxt prepare”,
“lint”: “eslint --ext .vue,.js,.ts --ignore-path .gitignore .”,
“lint:fix”: “eslint --ext .vue,.js,.ts --ignore-path .gitignore . --fix”
},
2、安装npm安装nuxt 在安装nuxt之前先更细npm版本
3、使用npm run build命令编译项目,编译完成后 拷贝,node_modules不需要每次都拷贝,文件没有变化只更新.nuxt 和 .output文件即可。
文件到服务上,服务器需要安装nuxt 命令,如果使用pm2 来启动,需要npm安装pm2
4、使用pm2启动,新建ecosystem.config.js
module.exports = {
apps: [
{
name: ‘nuxt-app’,
port: 端口,
exec_mode: ‘fork’,//cluster
instances: ‘1’,//max
script: ‘./.output/server/index.mjs’
}
]
}
5、执行命令 pm2 start ecossystem.config.js执行完以后可以使用netstat -nltp查看端口是否已经监听。