Skip to content

想问一下从umi3.x升级到4.x,有没有通过升级umi相关包的形式,而不是替换成@umijs/max的包的形式 #12163

Answered by fz6m
ZIA-Hans asked this question in Q&A
Discussion options

You must be logged in to vote

关于避免导入 umi 都更改为 @umijs/max 的问题,有两个解决办法。

第一个方法:在项目根目录新增一个项目级插件 plugin.ts

// plugin.ts

import { IApi } from '@umijs/max';

export default (api: IApi) => {
  api.modifyTSConfig(memo => {
    memo.compilerOptions.paths.umi = memo.compilerOptions.paths['@umijs/max']
    return memo
  })
};

因为 umi@umijs/max 导入的东西内容是一样的,只是称呼不一样,所以手动加一个 umi 的 TS 类型提示即可避免迁移 umi 导入名字。

  1. 初始化一个 umi 项目,而不是 max 项目,并手动添加使用的插件:
  pnpm i -D @umijs/plugins
// .umirc.ts

  plugins: [
    '@umijs/plugins/dist/access',
    '@umijs/plugins/dist/antd',
    // ...
  ],
  antd: {},
  access: {},
  // ...

max 和 umi 的区别是 max = umi + @umijs/plugins ,所以你手动添加进去就变成功能和 max 一样了,max 默认自带的插件参考:max/preset

注:在迁移升级的过程中,最好先初始化一个 max / …

Replies: 2 comments

Comment options

You must be logged in to vote
0 replies
Comment options

You must be logged in to vote
0 replies
Answer selected by ZIA-Hans
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
2 participants