学生管理系统-07打包与上线

一、项目架构

vue的项目必须要进行打包,并部署在nginx服务器上的

二、vue的打包

1、修改vue.cofing.js文件

在该文件中添加publicPath属性,值为./

javascript 复制代码
const { defineConfig } = require('@vue/cli-service')
module.exports = defineConfig({
  transpileDependencies: true,
  publicPath:'./'
})

2、修改router/index.js文件

javascript 复制代码
const router=new VueRouter({
    routes,
    mode:'hash',
    base:'/studentMgr/'
})

3、打包

在终端上执行如下命令

javascript 复制代码
npm run build

打包之后,会在项目的根目录下产生一个叫dist的文件夹,这个就是打包之后的文件

三、项目上线部署

1、更改dist的名称

这里我将dist的名称改为studentMgr

2、通过xftp等上传工具,将这个文件上传到/opt/

3、修改nginx的配置文件

该配置文件在/etc/nginx/conf.d

使用编辑软件将default.conf文件打开

javascript 复制代码
location /studentMgr {
   alias /opt/studentMgr;
   index index.html;
}

4、重启nginx服务器

  • 通过xshell等命令行工具进入到linux

  • 查看nginx进程状态

javascript 复制代码
[root@iZ2ze9412d3dcresdj7soqZ ~]# ps aux|grep nginx
root      5379  0.0  0.0  46476  1036 ?        Ss   15:38   0:00 nginx: master process /usr/sbin/nginx
nginx     5380  0.0  0.1  46928  2148 ?        S    15:38   0:00 nginx: worker process
root      9627  0.0  0.0 112704   972 pts/2    S+   16:20   0:00 grep --color=auto nginx
  • 杀死nginx进程
javascript 复制代码
[root@iZ2ze9412d3dcresdj7soqZ ~]# killall -9 nginx
  • 启动nginx
javascript 复制代码
[root@iZ2ze9412d3dcresdj7soqZ ~]# /usr/sbin/nginx

5、history模式下404的解决办法

  • 在etc/nginx/default.d文件中将配置项上添加tryfiles属性,具体配置如下
javascript 复制代码
location /studentMgr {
        alias /opt/studentMgr;
        index index.html;
        try_files $uri $uri/ /studentMgr/index.html;
 }
相关推荐
用户8417948145616 分钟前
vxe-gantt 甘特图在 Nuxt 中的集成与使用
vue.js
喵了几个咪40 分钟前
AI重构软件开发范式:框架与脚手架为何仍是生产级开发的刚需?
vue.js·人工智能·react.js·重构·golang·ai编程
lpd_lt3 小时前
服务端类vue等页面AI测试方向
前端·vue.js·人工智能
橘子味的冰淇淋~4 小时前
优化前端性能之从“全局引入”改为“按需引入”
前端·javascript·vue.js
Vennn4 小时前
Android自动化:使用 Web 方式实现某音未读消息检查与采集
前端·javascript·vue.js
皮皮大人4 小时前
Vue 3 响应式内核完全解密:reactive & effect 与 Vue 2 Watcher 史诗对决
前端·vue.js
暗中讨饭xdm5 小时前
立体echarts柱状图咋做
前端·vue.js·echarts
w_t_y_y6 小时前
vue父子组件通信(一)父子调用和通信(2)VUE3
前端·javascript·vue.js
Cheney95016 小时前
Vue 项目字体文件打包后 fonts 文件夹“消失”?原因分析与解决方案
前端·javascript·vue.js
daols886 小时前
vxe-table 实现数据分组统计与表尾合计
前端·javascript·vue.js·vxe-table