• Vue如何打包和部署应用到服务器?(Vue项目的打包和发布)
  • 发布于 1个月前
  • 45 热度
    0 评论
本文简要概述一下Vue前端项目如何打包部署。
1、打包
vue3是一个前端框架,最终的产物还是html,js,css。本地开发可以通过node.js起一个服务器进行调试(npm run serve),开发完成后需要将项目打包,所以最终还是要将打包产出dist扔到服务器上。
# 创建项目
vue create hello-star
# 安装依赖包
npm install
# 开发环境调试
npm run serve
# 打包
npm run build
2、部署
这里将dist扔到nginx中(也可以直接扔到后端的服务器中),开发中配置的devServer请求代理就没用了,需要在ng中进行代理配置。
http {
  include mime.types;
  default_type  application/octet-stream;
  server{    
    rewrite_log on;
    listen 80;
    server_name mnxm.test;
    charset utf-8;
    location / {
      root  /front/hello-star/dist;
      try_files $uri $uri/ /index.html;
      index  index.html index.htm;
    }
    location /api/ {
      proxy_pass http://mnxm.test:8787/;
    }
  }
}

用户评论