Command Line
umi offers many built-in command line interfaces to start and build projects, as well as some auxiliary development commands, such as generators.
To get a list of available commands, you can run the help command in the project directory:
umi help
You should see logs similar to the following:
Usage: umi <command> [options]Commands:build build app for productionconfig umi config clidev dev server for developmenthelp show commands helplint lint source code using eslint and stylelintsetup setup projectdeadcode check dead codeversion show umi versionv show umi versionplugin inspect umi pluginsverify-commit verify the commit message, which is usually used with husky.preview locally preview production buildrun run the script commands, support for ts and zxgenerate generate code snippets quicklyg generate code snippets quicklyRun `umi help <command>` for more information of specific commands.Visit https://umijs.org/ to learn more about Umi.
For ease of lookup, the commands below are sorted alphabetically.
build
Build the project for deployment in a production environment.
$ umi build
config
Quickly view and modify configuration via the command line.
Viewing configuration, you can use list
or get
.
$ umi config list- [key: polyfill] false- [key: externals] { esbuild: true }$ umi config get mfsu- [key: externals] { esbuild: true }
Modifying configuration, you can use set
or remove
.
$ umi config set polyfill falseset config:polyfill on /private/tmp/sorrycc-wsYpty/.umirc.ts$ umi config remove polyfillremove config:polyfill on /private/tmp/sorrycc-wsYpty/.umirc.ts
dev
Start a local development server for project development and debugging.
$ umi dev╔═════════════════════════════════════════════════════╗║ App listening at: ║║ > Local: https://127.0.0.1:8001 ║ready - ║ > Network: https://192.168.1.1:8001 ║║ ║║ Now you can open browser with the above addresses👆 ║╚═════════════════════════════════════════════════════╝event - compiled successfully in 1051 ms (416 modules)
generate
Used for incrementally generating files or enabling features, the command line alias is g
.
When used without any parameters, it will opt for an interactive generator selection.
$ umi g# or$ umi generate? Pick generator type › - Use arrow-keys. Return to submit.❯ Create Pages -- Create a umi page by page nameEnable Prettier -- Enable Prettier
You can also specify parameters.
# Generate route files$ umi g page index --typescript --less
help
View help.
$ umi helpUsage: umi <command> [options]Commands:build build app for productionconfig umi config clidev dev server for developmenthelp show commands helpsetup setup projectversion show umi versionplugin inspect umi pluginsgenerate generate code snippets quicklyRun `umi help <command>` for more information of specific commands.Visit https://umijs.org/ to learn more about Umi.
You can also specify a command to see detailed help for that command.
$ umi help buildUsage: umi build [options]build app for production.Details:umi build# build without compressionCOMPRESS=none umi build# clean and buildumi build --clean
lint
Used to check and correct code to match rules.
$ umi lintUsage: umi lintSupport for validation of js, ts, tsx, jsx type files only: umi lint --eslint-onlySupport for validation of css, less and other style files only: umi lint --stylelint-onlySupport for cssinjs mode validation: umi lint --stylelint-only --cssinjsCorrect the code: --fix
plugin
Plugin related operations, currently only supports the list
subcommand.
List all plugins.
$ umi plugin list- @umijs/core/dist/service/servicePlugin- @umijs/preset-umi (from preset)- @umijs/preset-umi/dist/registerMethods (from preset)- @umijs/preset-umi/dist/features/appData/appData (from preset)- @umijs/preset-umi/dist/features/check/check (from preset)- @umijs/preset-umi/dist/features/configPlugins/configPlugins (from preset)- virtual: config-styles- virtual: config-scripts- virtual: config-routes- virtual: config-plugins...
preview
The umi preview
command will launch a local static web server, running the dist folder at http://127.0.0.1:4172, for previewing the production build, supporting proxy, mock, etc. settings.
You can use the --port
parameter to configure the service's running port.
$ umi preview --port 9527
Now the preview
command will run the server at http://127.0.0.1:9527.
Use the --host
parameter to specify the service's running hostname.
The following user configurations will also take effect during preview
Note that the dist
directory will change with the configuration of outputPath
.
run
The umi run
command allows you to run TypeScript and ESM files like running js with node. You can pair it with zx for better script command usability.
$ umi run ./script.ts
setup
Initialize the project, doing operations like generating temporary files. Usually set in scripts.postinstall
in package.json.
{"scripts": { "postinstall": "umi setup" }}
deadcode
Used to find files in the src directory that are not referenced, and output to the root directory.
$ umi deadcode- Preparing...- begin check deadCode- write file /examples/umi-run/DeadCodeList-{timeStamp}.txt- check dead code end, please be careful if you want to remove them
mfsu
The umi mfsu
command can be used to view MFSU dependency information, rebuild MFSU dependencies, and clear MFSU dependencies.
$ umi mfsu
$ umi mfsu lswarning@4.0.3regenerator-runtime/runtime.js@0.13.11react/jsx-dev-runtime@18.1.0react-intl@3.12.1react-error-overlay/lib/index.js@6.0.9react@18.1.0qiankun@2.8.4lodash/noop@4.17.21lodash/mergeWith@4.17.21lodash/concat@4.17.21...
$ umi mfsu buildinfo - Preparing...info - MFSU eager strategy enabledwarn - Invalidate webpack cache since mfsu cache is missinginfo - [MFSU] buildDeps since cacheDependency has changed...info - [plugin: @umijs/preset-umi/dist/commands/mfsu/mfsu] [MFSU][eager] build success
$ # Delete dependency information list$ umi mfsu remove$ # Delete dependency information list and product files$ umi mfsu remove --all
verifyCommit
Verify commit message information, usually used in conjunction with husky.
For example, configure the following in .husky/commit-msg
,
#!/bin/sh. "$(dirname "$0")/_/husky.sh"npx --no-install umi verify-commit $1
version
View the umi
version, equivalent to umi -v
.
$ umi version4.0.0