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

使用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.lryc.cn/news/2383692.html

相关文章:

  • 从0到1打造AI Copilot:用SpringBoot + ChatGPT API实现智能开发助手
  • LeetCode Hot100 (双指针)
  • JVM常量池(class文件常量池,运行时常量池,字符串常量池)
  • 开源免费无广告专注PDF编辑、修复和管理工具 办公学术 救星工具
  • 鸿蒙Flutter实战:24-混合开发详解-4-初始化Flutter
  • 我爱学算法之—— 二分查找(中)
  • Golang 并发小结
  • RTC技术
  • 基于Matlab建立不同信道模型
  • uni-app 排坑
  • 军事目标系列之迷彩作战人员检测数据集VOC+YOLO格式2755张1类别
  • Qt C++实现马的遍历问题
  • node12.22.12在nvm中安装
  • 技术篇-2.3.Golang应用场景及开发工具安装
  • 高效缓存设计的哲学
  • 【生态信息】开源软件全方位解析
  • FastAPI在 Nginx 和 Docker 环境中的部署
  • 计算机网络相关面试题
  • 根据当前日期计算并选取上一个月和上一个季度的日期范围,用于日期控件的快捷选取功能
  • 【C++】set、map 容器的使用
  • 【MySQL】第1节|全面理解MySQL架构
  • YOLOv8模型剪枝笔记(DepGraph和Network Slimming网络瘦身)
  • App Builder技术选型指南:从AI编程到小程序容器,外卖App开发实战
  • TDengine 高可用——三副本
  • el-table高度自适应、数据查询后高度展示错误问题
  • 【蓝桥杯真题精讲】第 16 届 Python A 组(省赛)
  • Java接口设计:ECharts热力图的绘制
  • 深入理解 MongoDB 的 _id 和 ObjectId:从原理到实践
  • C++内存复制
  • 【notepad++如何设置成中文界面呢?】