当前位置: 首页 > 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

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

相关文章:

  • 【IC_Design】跨时钟域的寄存器更新后锁存
  • RK3588 RGA 测试
  • 解决leetcode第3548题.等和矩阵分割II
  • 推测解码算法在 MTT GPU 的应用实践
  • C++23 容器推导指引中对于分配器的非推导语境(P1518R2)
  • MCP协议:AI时代的“万能插座”,如何重塑互联网技术生态?
  • 【1004. 最大连续1的个数 III】
  • Redis进阶之高可用
  • 操作系统学习笔记第1章 操作系统概述(灰灰题库
  • SAR ADC 的常见架构
  • Spring Task
  • 结课作业自选01. 内核空间 MPU6050 体感鼠标驱动程序(二)(完整实现流程)
  • 服务器硬盘分类
  • 服务器磁盘按阵列划分为哪几类
  • 【Vue】将响应式对象转为非响应式对象
  • (37)服务器增加ipv6配置方法
  • 浪潮Inspur服务器产品线概述
  • van-picker实现日期时间选择器
  • fatal error: uuid/uuid.h: No such file or directory 编译问题修复。
  • linux杀死进程自身
  • 北湖区网站建设公司哪家好/千锋教育培训机构地址
  • 个人制作的网站/免费的seo网站
  • 深圳多语言网站建设/百度网址大全旧版
  • 蒙山县网站建设/关键词优化的发展趋势
  • 网站备案 论坛/网络运营师
  • 做塑料哪个网站好/惠州seo排名