两个事, 一乌米项目打包时路径的配置, 二nginx 在docker上的操作。
一、umi 项目路径配置
通常用 .umirc.ts 来配置, 与项目访问路径相关的配置如下:
export default defineConfig({
// 这个路径配置后,umi build 出来的index.html文件中,
// 会在你引入的 js, css 等文件路径前加上 projectPath,
// 如: <script src=''/projectPath/umi.js" />
publicPath: '/projectPath/',
// 此处是会在build出的index.html中设置 window.routerBase = "/projectPath/",
base: '/projectPath/',
...
})
image.png
image.png
二、nginx 发布
借着这个项目学习了下前端项目直接部署到 nginx 相关的配置, 因为ng 是docker的, 顺带也熟悉了一下portainer的配置。
如果应用是部署在域名的子路径上,那么umi项目需要配置publicPath 和 base; 如果是根路径上,可不用设置。
nginx 配置
在config.d目录修改defautl.config文件
location /projectPath{
// $uri $uri/ 区别在于访问路径后加不加'/'
try_files $uri $uri/ /projectPath/index.html;
index index.html index.htm;
root /usr/share/nginx;
}
可以使用
nginx -t
来检测配置文件语法是否有问题
nginx -s reload
重启
网友评论