大前端

UmiJS学习与实战系列 · 非根目录配置部署

2021-10-23  本文已影响0人  天問_专注于大前端技术

当使用VueReact等框架来构建项目,一般都是生成的SPA应用(单页面应用)。
如果一个域名(服务器)要部署多个这种SPA应用,就需要做打包配置,页面才能正常的加载和访问。

UmiJS-Deploy

项目打包配置

import { defineConfig } from 'umi'

export default defineConfig({
  // ...
  history: {
    type: 'browser',  // 浏览器history模式,无 # 号   
  },
  base: '/admin/',
  publicPath: '/admin/',
  // ...
})

注意: 相对路径 ./ 有一些限制,例如不支持多层路由 /foo/bar,只支持单层路径 /foo

运行 npm run dev

> start
> umi dev

  App running at:
  - Local:   http://localhost:8000 (copied to clipboard)
  - Network: http://xx.xxx.xx.xx:8000

访问时会自动加上添加的目录

nginx部署配置

# 静态服务
server {
    listen       8080;
    server_name  127.0.0.1;

    location / {
        root   /data/www/tiven-web; // 打包后的静态文件目录
        index  index.html index.htm;
        try_files $uri $uri/ /index.html;
    }
}

# 反向代理
location /admin/ {
    proxy_pass   http://127.0.0.1:8080/;
}

《UmiJS学习与实战》系列


欢迎访问:个人博客地址

上一篇下一篇

猜你喜欢

热点阅读