-
快速上手
- 安装node,使用yarn管理npm依赖: npm i yarn -g
- 搭建脚手架:yarn creat @umijs/umi-app
- 安装依赖:yarn 或者 yarn install
- 启动项目:yarn start
- 修改相关配置在.umirc.ts文件 或 config/fonfig.ts 文件修改
- 部署发布:yarn build
- 本地验证:通过yarn build打包的文件需要在服务环境下才能开启,所以需要通过node安装serve服务
- 执行:yarn global add serve 安装服务
- 执行:serve ./ dist 开启服务
- 本地验证完,就可以部署了
-
目录结构
-
package.json:包含插件和插件集,以
@umijs/preset-
、@umijs/plugin-
、umi-preset-
和umi-plugin
-
开头的依赖会被自动注册为插件或插件集 -
.umirc.ts:配置文件,包含 umi 内置功能和插件的配置。
-
dist :执行
umi build
后,产物默认会存放在这里。 -
mock :存储 mock 文件,此目录下所有 js 和 ts 文件会被解析为 mock 文件。
-
public :存放项目中的静态文件
-
src/.umi : 临时文件
-
src/layouts/index.tsx: 约定式路由时的全局布局文件。
-
pages 目录: 所有路由组件存放
-
app.ts : 运行是的配置文件
-
-
常用配置:
.umirc.ts
或config/config.ts
中配置项目和插件-
base: 跟目录加前缀 /admin
-
publishPath: 资源配置目录
-
outputPath:打包输出文件目录 dist ==> build
-
title标题: 网站的标题title
-
history:{type:"hash/browser";Default:{}}
-
proxy代理:{}
-
theme主题配置:theme:{'@primary-color': '#1DA57A',}
-
routes路由配置:routes: [ { path: '/', component: '@/pages/index' }, ],
import { defineConfig } from 'umi'; export default defineConfig({ nodeModulesTransform: { type: 'none', }, base: "", title: "首页", theme:{...}, routes: [ { path: '/', component: '@/pages/index' }, ], fastRefresh: {}, });
-
-
路由配置
- 默认配置路由,看代码
export default { routes: [ { path: '/login', component: 'login' }, { path: '/', component: '@/layouts/index', routes: [ { path: '/list', component: 'list' }, { path: '/admin', component: 'admin' }, ], }, ], }
- 重定向redirect
export default { routes: [ { exact: true, path: '/', redirect: '/list' }, { exact: true, path: '/list', component: 'list' }, ], }
- history路由相关参数等
match,当前路由和 url match 后的对象,包含 params、path、url 和 isExact 属性 location,表示应用当前处于哪个位置,包含 pathname、search、query 等属性 history,同 api#history 接口 route,当前路由配置,包含 path、exact、component、routes 等 routes,全部路由信息
- 默认配置路由,看代码
-
等等。。。
umi 实战学习
最新推荐文章于 2024-04-30 16:13:21 发布