node vue 项目部署问题汇总

场景:vue-router为history模式,不带项目名访问的部署,如果资源是用相对路径加载,则资源匹配路径不对

一、带项目名称访问,如部署到tomcat服务上

webpack: 

build/utils.js  -- publickPath改成相对路径: '../../'

config/index.js -- assetsPublicPath改成相对路径: './'

二、不带项目名访问,如部署到nginx服务上

需要的改动:

nginx.conf

location / {
    root   html;
    index  index.html index.htm;
    try_files $uri $uri/ /index.html; //特别设置的地方: 解决 http://IP:port/xxx/xxx 出现404的问题
    #error_page  404   /404.html;
}

webpack:

build/utils.js  -- publickPath置空: ''

config/index.js -- assetsPublicPath改成绝对路径: '/'

vue项目部署中遇到的问题,以作备忘。

猜你喜欢

转载自www.cnblogs.com/xtreme/p/10309867.html