Vue-cli项目开发好了,到了部署的阶段,中途遇见了很多坑,特此记录以下
1:打包:
npm run build
问题一:刷新页面404
nginx配置:
server {
listen 9093;
server_name 172.16.93.39;
root /opt/push/apply_vue/;
index index.html;
location ~* ^.+\.(jpg|jpeg|gif|png|ico|css|js|pdf|txt){
root /opt/push/apply_vue/;
}
# 下面配置主要是页面重新调转
location / {
try_files $uri $uri/ @router;
index index.html;
}
location @router {
rewrite ^.*$ /index.html last;
}
}
~问题二:刷新页面正常,资源文件路径错误
修改config中的index.js,将./改为/。重新打包
build{
# 指定路径为绝对路径
assetsPublicPath: '/',
}