First you need to install node. Make sure the node version is 10.13 or above. (nvm is recommended to manage node version for Mac OSX)
$ node -vv10.13.0
We recommend to use yarn to manage npm dependencies.
# install yarn globally$ npm i yarn -g# confirm yarn version$ yarn -v
We recommend to use tyarn to improve performance:
# install tyarn globally$ npm i yarn tyarn -g# confirm tyarn version$ tyarn -v# install yarn and @ali/yarn globally$ tnpm i yarn @ali/yarn -g# confirm ali yarn version$ ayarn -v
Create an empty directory for your app
$ mkdir myapp && cd myapp
Create project using @umijs/umi-app
as the template
$ yarn create @umijs/umi-app // if use yarn$ npx @umijs/create-umi-app // if use npmCopy: .editorconfigWrite: .gitignoreCopy: .prettierignoreCopy: .prettierrcWrite: .umirc.tsCopy: mock/.gitkeepWrite: package.jsonCopy: README.mdCopy: src/pages/index.lessCopy: src/pages/index.tsxCopy: tsconfig.jsonCopy: typings.d.ts
$ yarnyarn install v1.21.1[1/4] 🔍 Resolving packages...success Already up-to-date.✨ Done in 0.71s.
$ yarn startStarting the development server...✔ WebpackCompiled successfully in 17.84sDONE Compiled successfully in 17842ms 8:06:31 PMApp running at:- Local: http://localhost:8000 (copied to clipboard)- Network: http://192.168.12.34:8000
Open http://localhost:8000/ in your browser, you can see the following interface
The default scaffolding has built-in @umijs/preset-react
, including common functions such as layout, permissions, internationalization, dva, and simple data flow. For example you want ant-design-pro layout, editing .umirc
.ts configuration layout: {}
import { defineConfig } from 'umi';export default defineConfig({+ layout: {},routes: [{ path: '/', component: '@/pages/index' },],});
No need to restart yarn start
, webpack will compile incrementally behind the scenes, you will see the following interface after a while
$ yarn build✔ WebpackCompiled successfully in 17.17sDONE Compiled successfully in 17167ms 8:26:25 PMBuild success.✨ Done in 20.79s.
Build is generated by default in ./dist
. We can the distribution as a tree
tree ./dist./dist├── index.html├── umi.css└── umi.js
Before publishing, you can serve
check the build locally.
$ yarn global add serve$ serve ./dist┌────────────────────────────────────────────────────┐│ ││ Serving! ││ ││ - Local: http://localhost:5000 ││ - On Your Network: http://192.168.12.34:5000 ││ ││ Copied local address to clipboard! ││ │└────────────────────────────────────────────────────┘
Access http://localhost:5000 and built assets from ./dist
folder will be served.
After local verification, you can deploy. You will need to deploy the dist
directory to the server.