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
eslintconfiguration package with@umijs/max/eslint, reducing the rules - Add
lintstagerelated configurations and make adjustments - Append to
npmrc - Remove
nvmrc - Move
config.tschanges intoumirc.ts - Adjust
config.tscontent, refer to Upgrade to Umi 4 - Remove all
webpack-chainplugin related configurations; the related packages can basically be removed from the project proxyrelated configurations are not needed- Remove all
mockdata and related items, they are not needed - Replace
package.jsonwith the latest umijs 4 related dependencies, and add essential difference packages required by the project that are not included inumijs/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.tsto rewrite fine-grained permission support - Rewrite
app.tsaccording to the original content and previous page configurations - Rewrite some components, change
class componentstofunction components, usehooksto obtain related resources instead ofprops - Rewrite child components, use
Outlet - Replace package references in code with
@umijs/max - Upgrade
antd,antd pro,antd iconto the latest versions, removelessrelated dependencies - Do not use
internationalization, temporarily remove all related parts - Handle
namepaceconflicts indwausing the exclusion method - Replace
PageHeaderWrapperwithPageContainer - Deprecate
umi-request, useaxiosinstead - Replace
import * as moment from 'moment'withimport 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.
Comments (0)
No comments yet. Be the first to leave one!