学生管理系统-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;
 }
相关推荐
达子6661 小时前
第26章_HarmonyOs开发图解之 设备管理
vue.js
自然 醒1 小时前
v-tooltip自定义指令封装
前端·javascript·vue.js
万敏5 小时前
Vue3 全栈实战第四周:watch、nextTick、性能优化与 keep-alive 实战记录
vue.js·node.js·全栈
布兰妮甜5 小时前
Vue 大型页面性能优化:四个核心策略
vue.js·性能优化·虚拟滚动·组件缓存·按需加载
di24k24k5 小时前
多个 el-form 共用同一 ref 导致表单校验部分失效
前端·javascript·vue.js·elementui
执子念的飞鱼8 小时前
Vue 3 文件预览落地:鉴权 Blob、Worker/WASM 与内网子路径部署
vue.js·webassembly
无人生还8 小时前
从 Vue3 到 React · 快速上手系列第 11 篇:状态管理
前端·vue.js·react.js
其美杰布-富贵-李9 小时前
Vue 3 模块导入教程:import、export 与文件组织
前端·javascript·vue.js
布兰妮甜9 小时前
Vue 路由进阶:路由守卫权限控制、动态路由、懒加载、路由缓存
vue.js·懒加载·动态路由·路由守卫权限控制·路由缓存
Cobyte9 小时前
Vite & Rollup 插件开发实践
前端·javascript·vue.js