当前位置: 首页 > news >正文

使用pm2 部署react+nextjs项目到服务器

记录一下
next.config.js中:

output: 'standalone',

package.json配置:

  "scripts": {"dev": "cross-env NODE_OPTIONS='--inspect' next dev","build": "next build","start": "cp -r .next/static .next/standalone/.next/static && cp -r public .next/standalone/public && cross-env PORT=$npm_config_port HOSTNAME=$npm_config_host node .next/standalone/server.js","lint": "pnpm eslint --cache --cache-location node_modules/.cache/eslint/.eslint-cache","lint-only-show-error": "pnpm eslint --cache --cache-location node_modules/.cache/eslint/.eslint-cache --quiet","fix": "next lint --fix","eslint-fix": "eslint --cache --cache-location node_modules/.cache/eslint/.eslint-cache --fix","eslint-fix-only-show-error": "eslint --cache --cache-location node_modules/.cache/eslint/.eslint-cache --fix --quiet","eslint-complexity": "eslint --rule 'complexity: [error, {max: 15}]' --quiet","prepare": "cd ../ && node -e \"if (process.env.NODE_ENV !== 'production'){process.exit(1)} \" || husky ./web/.husky","gen-icons": "node ./app/components/base/icons/script.mjs","uglify-embed": "node ./bin/uglify-embed","check-i18n": "node ./i18n/check-i18n.js","auto-gen-i18n": "node ./i18n/auto-gen-i18n.js","test": "jest","test:watch": "jest --watch","storybook": "storybook dev -p 6006","build-storybook": "storybook build"},

react+nextjs项目打包后会生成一个.next文件

在这里插入图片描述

里面文件目录如下,有很大的cache,可以删掉
在这里插入图片描述
在这里插入图片描述

看网上的说法是,部署只需要打包出的这个.next文件,但我只用它,部出来的根本无法访问
这个后面再看看吧


安装PM2

npm install pm2@latest -g

在这里插入图片描述
在代码文件目录下执行,不是.next/standalone/下:

 pm2 start npm --name 自己命名 -- run start

在这里插入图片描述
在这里插入图片描述
成功

http://www.xdnf.cn/news/585847.html

相关文章:

  • (Java基础笔记vlog)Java中常见的几种设计模式详解
  • java接口自动化(四) - 企业级代码管理工具Git的应用
  • 理解全景图像拼接
  • 动态网页爬取:Python如何获取JS加载的数据?
  • Jenkins与Maven的集成配置
  • C++中的string(1)简单介绍string中的接口用法以及注意事项
  • Web前端开发 - 制作简单的焦点图效果
  • 单例模式的运用
  • UniApp+Vue3微信小程序二维码生成、转图片、截图保存整页
  • uniapp实现的简约美观的票据、车票、飞机票模板
  • ffmpeg 转换视频格式
  • 【Windows】FFmpeg安装教程
  • 「Python教案」运算符的使用
  • 中国计算机学会——2024年9月等级考试5级——第四题、森森快递(贪心+线段树)
  • JavaScriptAPIs学习day3--事件高级
  • 破局制造业转型: R²AIN SUITE 提效实战教学
  • Unity3D 异步加载材质显示问题排查
  • Python安全密码生成器:告别弱密码的最佳实践
  • TRC20代币创建教程指南
  • 解决 IntelliJ IDEA 配置文件中文被转义问题
  • ClickHouse核心优势分析与场景实战
  • 论文流程图mermaid解决方案
  • uni-app学习笔记八-vue3条件渲染
  • 打卡Day34
  • 绕距#C语言
  • IP大科普:住宅IP、机房IP、原生IP、双ISP
  • Keepalived 与 LVS 集成及多实例配置详解
  • React 与 TypeScript 极客园移动端
  • OpenCV CUDA模块图像过滤------用于创建一个最小值盒式滤波器(Minimum Box Filter)函数createBoxMinFilter()
  • Android 内存溢出(OOM)的 Kotlin 排查与优化指南