I have an older project that uses the umijs 3 frontend framework, and an even older one that uses umijs 2. Recently, I upgraded umijs 3 to 4 and, after testing, deployed it to the production environment. Here is a review and record of the upgrade process.

Reason for Upgrade

umijs 4 has been released for a while now. umijs 4 Currently, the common issues encountered in projects are the wait time after editing code and occasional unexpected command-line exits. These are efficiency problems during development. Another aspect is removing unused code and redundant libraries during upgrades, retaining only the minimal set of libraries required by the system. This is one of the goals. The other goal is to enforce engineering checks, such as mandatory use of ts, eslint, and prettier, to eliminate inexplicable and undesirable code in the project.

Upgrade Process

The overall approach is to create a new umijs 4 project, then copy the code into the new project until it runs successfully with no basic functionality issues, and then migrate it back to the original project.

  • Replace the eslint configuration package with @umijs/max/eslint, reducing the rules
  • Add lintstage related configurations and make adjustments
  • Append to npmrc
  • Remove nvmrc
  • Move config.ts changes into umirc.ts
  • Adjust config.ts content, refer to Upgrade to Umi 4
  • Remove all webpack-chain plugin related configurations; the related packages can basically be removed from the project
  • proxy related configurations are not needed
  • Remove all mock data and related items, they are not needed
  • Replace package.json with the latest umijs 4 related dependencies, and add essential difference packages required by the project that are not included in umijs/max
  • Rewrite the permission part, dynamically render routes based on the logged-in user, dynamically generate the menu based on the rendered routes, and add access.ts to rewrite fine-grained permission support
  • Rewrite app.ts according to the original content and previous page configurations
  • Rewrite some components, change class components to function components, use hooks to obtain related resources instead of props
  • Rewrite child components, use Outlet
  • Replace package references in code with @umijs/max
  • Upgrade antd, antd pro, antd icon to the latest versions, remove less related dependencies
  • Do not use internationalization, temporarily remove all related parts
  • Handle namepace conflicts in dwa using the exclusion method
  • Replace PageHeaderWrapper with PageContainer
  • Deprecate umi-request, use axios instead
  • Replace import * as moment from 'moment' with import moment from 'moment'
  • Adjust tsconfig.json, remove unnecessary configurations

Afterword

The content above may not be very useful for most users who are also upgrading from umijs3 to umijs4. Generally, it is more reliable to provide specific error messages and their corresponding solutions. However, the errors and issues encountered during the upgrade have mostly been resolved by finding relevant information. It would be best to document the process while upgrading next time, as this would be more helpful for others who may need to refer to it in the future. Let this serve as a lesson. Thanks to the teachers in the Telegram UmiJS Official Community Group for their help and answers.