构建
当项目开发完毕,只需要运行一行命令就可以打包你的应用:
npm run build
构建打包成功之后,会在根目录生成 dist 文件夹,里面就是构建打包好的文件,通常是 .js、.css、index.html 等静态文件。
分析构建文件体积
如果你的构建文件很大,你可以通过 analyze 命令构建并分析依赖模块的体积分布,从而优化你的代码。
npm run analyze
上面的命令会自动在浏览器打开显示体积分布数据的网页。
部署
将构建完成的dist下的所有文件复制到/nginx/html目录下,然后配置/nginx/conf/nginx.conf
server {
listen 80;
server_name localhost;
root /usr/nginx/html;
location / {
#防止刷新页面,页面404
try_files $uri /index.html;
}
#配置代理路由至后端服务
location /auth/ {
proxy_pass http://12.3.10.124:9092/auth/;
}
location /agt/ {
proxy_pass http://12.3.10.124:9092/agt/;
}
location /merc/ {
proxy_pass http://12.3.10.124:9092/merc/;
}
location /pub/ {
proxy_pass http://12.3.10.124:9092/pub/;
}
location /tms/ {
proxy_pass http://12.3.10.124:9092/tms/;
}
location /risk/ {
proxy_pass http://12.3.10.124:9092/risk/;
}
location /report/ {
proxy_pass http://12.3.10.124:9092/report/;
}
error_page 500 502 503 504 /50x.html;
location = /50x.html {
root html;
}
}
启动nginx
./nginx/sbin/nginx
重启nginx
./nginx/sbin/nginx -s reload
网友评论