Home

Awesome

AUmi

<p> <a href="https://npmjs.com/package/@aumi/aumi"> <img src="https://img.shields.io/npm/v/@aumi/aumi?style=flat-square" alt="npm version" /> </a> </p>

Build Umi based on Rsbuild

English | 简体中文

AUmi switches Umi's default bundler from Webpack to Rsbuild

Features

Migration

Notice: Make sure your Umi version is >= 4.0

Notice: V

Installation

npm add @aumi/aumi@latest -S

File changes

Updating .umirc.ts :

- import { defineConfig } from 'umi';
+ import {defineAUMIConfig} from "@aumi/aumi";

- export default defineConfig({
+ export default defineAUMIConfig({
  ...,
});

Due to compatibility or lacking of testing, cannot support the following configurations.

FieldUnsupported ReasonReplacement method
autoprefixerUse another approach1. use browserlist<br/>2. targets configuration of .umirc.ts
cssMinifierUse another approachminify configuration of .umirc.ts
classPropertiesLooseThis is a babel configuration in Umi, Rsbuild uses swc by defaultswcLoader configuration of .umirc.ts
deadCodeWebpack plugin, rspack compatibility is no testedNone
depTranspilerNot used in @umijs/bundler-webpackNone
esbuildMinifyIIFEFix the namespace conflict caused by global variables automatically introduced by the esbuild compressor, not neededNone
extraBabelIncludesSwitching to extraIncludes configurationextraIncludes configuration of .umirc.ts
extraBabelPluginsSwitching to swcLoader configurationUse swcLoader configuration of .umirc.ts, check Rsbuild for details
extraBabelPresetsAs aboveAs above
exportStaticNot tested
extraPostCSSPluginsSwitching to postcssLoader configurationUse postcssLoader configuration of .umirc.ts, check Rsbuild for details
forgetNot testedNone
jsMinifierSwitching to minify configurationUse minify configuration of .umirc.ts, check Rsbuid for details
jsMinifierOptionsAs aboveAs above
legacyNot supportedNone
mdxNot supportedUse chainWebpack function of .umirc.ts
mfsuNot testedUse new added configuration moduleFederation of .umirc.ts, check Rsbuild for details
runtimePublicPathHasn't test compatibility of webpack plugin RuntimePublicPathPluginNone
srcTranspilerNot supported, use swcLoaderNone
srcTranspilerOptionsAs aboveNone

defineAUMIConfig has comprehensive TypeScript typing support except Umi plugins' typing

Updating package.json

Updating scripts field of package.json.

{
  "scripts": {
-   "dev": "umi dev",
+   "dev": "aumi dev",
-   "build": "umi build",
+   "build": "aumi build",
+   "analyze": "RSDOCTOR=true aumi build",
-   "postinstall": "umi setup",
+   "postinstall": "aumi setup",
-   "setup": "umi setup",
+   "setup": "aumi setup",
    "start": "npm run dev"
  }
}

The analyze command replaces Umi's analyze functionality by using Rsdoctor.

Start a new Project

Take Umi Getting Started as a reference to start a new project, and follow instructions above Migration

Other changes

New configuration in .umirc.ts

FieldDefault valueUsage
rsbuildConfigundefinedFull RsbuildConfig and has higher priority than other configs, will be merged by mergeRsbuildConfig, Reference
aliasStrategy'prefer-alias'The strategy of alias configuration, Reference
transformImportundefinedSimilar to babel-plugin-import, Reference
reactreferenceThe configuration of Rsbuild plugin @rsbuild/plugin-react, Reference
rspackundefinedModify rspack configuration, Reference

Changes of Umi plugins' extended methods

Umi provides massive extended methods by its plugin mechanism Umi Plugin Api. Due to we switch the bundler from @umijs/bundler-webpack to Rsbuild, some underlying build processes are inconsistent with @umijs/bundler-webpack. As a result, certain custom methods have been removed, if any removed methods are called, an error will be thrown out.

Remove extended methods as below, most are Babel related:

Add new extended methods for Rsbuild

Example:

api.modifyRsbuildPlugins(plugins => {
  return plugins.slice(1);
});

example:

api.modifyRsbuildConfig(config => {
  config.root = './';
  return config;
});

Remain issues

TODO