centOS部署VUE项目

本文档介绍了如何将Vue项目本地打包,并上传至CentOS服务器。通过创建app.js文件配置静态服务器,设置监听端口8080。在安装过程中遇到npm报错,但最终成功运行并使用PM2管理应用进程,包括启动、停止、删除和重启等操作。
摘要由CSDN通过智能技术生成

1.本地打包

本地使用以下命令打包,得到dist目录

npm run build

2.上传到服务器

将项目打包的dist以及package.json的文件上传到centos服务器
我的目录如下:
vue打包到centos服务器

3.新建app.js文件

内容如下:

//定义目录
const fs = require('fs');
const path = require('path');
const express = require('express');
const app = express();
//vue目录
app.use(express.static(path.resolve(__dirname, './dist')))

app.get('*', function(req, res) {
    const html = fs.readFileSync(path.resolve(__dirname, './dist/index.html'), 'utf-8')
    res.send(html)
})
//定义启动的端口号
app.listen(8080);

4.在这个目录里面执行运行操作

如果install的时候报错了,上面写的
:报错如下,以及类似的,建议使用非root账户进行install
npm WARN optional SKIPPING OPTIONAL DEPENDENCY: fsevents@1.2.9 (node_modules/fsevents):
npm WARN notsup SKIPPING OPTIONAL DEPENDENCY: Unsupported platform for fsevents@1.2.9: wanted {“os”:“darwin”,“arch”:“any”} (current: {“os”:“linux”,“arch”:“x64”})

npm ERR! code ELIFECYCLE
npm ERR! errno 1
npm ERR! yorkie@2.0.0 install: node bin/install.js
npm ERR! Exit status 1
npm ERR!
npm ERR! Failed at the yorkie@2.0.0 install script.
npm ERR! This is probably not a problem with npm. There is likely additional logging output above.

npm install
pm2 start app.js

install成功截图如下:
install成功

5. pm2相关命令

pm2 start app.js 开始进程
pm2 stop id 停止进程
pm2 delete id 删除进程
pm2 restart id 重启进程

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值