--- order: 3 title: Real project with dva --- [dva](https://github.com/dvajs/dva) is a React and redux based, lightweight and elm-style framework, which supports side effects, hot module replacement, dynamic on demand, react-native, and SSR. It has been widely used in production environments. This article will guide you to create a simple application from zero using dva and antd. Include the following: --- ## Install dva-cli Install dva-cli with npm, and make sure the version is later than `0.9.1`. ```bash $ npm install dva-cli -g $ dva -v dva-cli version 0.9.1 ``` ## Create New App After you have installed dva-cli, you can have access to the `dva` command in terminal ([can't access?](http://stackoverflow.com/questions/15054388/global-node-modules-not-installing-correctly-command-not-found)). Now, create a new application with `dva new`. ```bash $ dva new dva-quickstart ``` This creates a `dva-quickstart` directory, that contains the project directories and files, and provides a development server, build script, mock service, proxy server and so on. Then `cd` to the `dva-quickstart` directory, and start the development server. ```bash $ cd dva-quickstart $ npm start ``` After a few seconds, you will see the following output: ```bash Compiled successfully! The app is running at: http://localhost:8000/ Note that the development build is not optimized. To create a production build, use npm run build. ``` Open http://localhost:8000 in your browser, you will see the dva welcome page. ## Integrate antd Install `antd` and `babel-plugin-import` with npm. `babel-plugin-import` is used to automatically import scripts and stylesheets from antd on demand. See [repo](https://github.com/ant-design/babel-plugin-import) 。 ```bash $ npm install antd babel-plugin-import --save ``` Edit `.webpackrc` to integrate `babel-plugin-import`. ```diff + "extraBabelPlugins": [ + ["import", { "libraryName": "antd", "libraryDirectory": "es", "style": "css" }] + ], ``` > Notice: dva-cli's build and dev is based on roadhog, view [roadhog#Configuration](https://github.com/sorrycc/roadhog/blob/master/README_en-us.md#configuration) for more `.webpackrc` Configuration. ## Define Router We need to write an application displaying the list of products. The first step is to create a route. Create a route component `routes/Products.js`: ```javascript import React from 'react'; const Products = (props) => (
## Build Now that we've written our application and verified that it works in development, it's time to get it ready for deployment to our users. To do so, run the following command: ```bash $ npm run build ``` After a few seconds, the output should be as follows: ```bash > @ build /private/tmp/myapp > roadhog build Creating an optimized production build... Compiled successfully. File sizes after gzip: 82.98 KB dist/index.js 270 B dist/index.css ``` The `build` command packages up all of the assets that make up your application —— JavaScript, templates, CSS, web fonts, images, and more. Then you can find these files in the `dist /` directory. ## What's Next We have completed a simple application, but you may still have lots of questions, such as: - How to deal with async logic - How to load initial data elegantly - How to handle onError globally and locally - How to load Routes and Models on demand - How to implement HMR - How to mock data - and so on... You can: - Visit [dva official website](https://github.com/dvajs/dva). - Be familiar with the [8 Concepts](https://github.com/dvajs/dva/blob/master/docs/Concepts.md), and understand how they are connected together - Know all [dva APIs](https://github.com/dvajs/dva/blob/master/docs/API.md) - Checkout [dva knowledgemap](https://github.com/dvajs/dva-knowledgemap), including all the basic knowledge with ES6, React, dva - Checkout [more FAQ](https://github.com/dvajs/dva/issues?q=is%3Aissue+is%3Aclosed+label%3Afaq) - If your project is created with [dva-cli](https://github.com/dvajs/dva-cli) , checkout how to [Configure it](https://github.com/sorrycc/roadhog#configuration)