固然!公司内用于生产环境的项目估计已经有 3+ 。html
不支持。react
$ git clone https://github.com/Cherry-Team/lucian.git $ cd lucian $ npm install $ npm start
几秒以后,你将会看到如下输出webpack
import React, { Component } from 'react'; import { Button } from 'antd'; class Index extends Component { constructor(props) { super(props); } render() { return ( <Button>Button</Button> ); } } export default Index;
咱们要写个应用来显示列表,首先是建立路由。git
新建 route component pages/List.js
,内容以下:github
import React from 'react'; const List= (props) => ( <h2>List</h2> ); export default List;
添加路由信息到路由表,编辑 routeConfig.js
web
const List = lazy(() => import(/* webpackChunkName: "List"*/'./pages/List/index')); const routes = [ { path: '/list', component: List } ];
随着应用的发展,你会须要在多个页面分享 UI 元素 (或在一个页面使用屡次),根目录下新建components/LayoutHeader/index.jsx
npm
import React, { Component } from 'react'; import { Avatar, Dropdown, Menu } from 'antd'; const menu = ( <Menu> <Menu.Item> <a target="_blank" rel="noopener noreferrer" href={false}> 退出 </a> </Menu.Item> </Menu> ); class Index extends Component { constructor(props) { super(props); this.state = {}; } render() { return ( <section> <div> 订单系统 </div> <div> <span>消息</span> <Dropdown overlay={menu}> <div> <Avatar size={28} icon="user" /> <span >Faker</span> </div> </Dropdown> </div> </section> ); } } export default Index;
新建pages/Counter/index.jsx
redux
import React, { Component } from 'react'; import { connect } from 'react-redux'; import * as action from '../../actions/counter'; import './index.less'; const mapStateToProps = state => { const { counter } = state; return { counter: counter.toJS() }; }; const mapDispatchToProps = (dispatch) => ({ add: (...args) => dispatch(action.add(...args)), reduce: (...args) => dispatch(action.reduce(...args)) }); class Index extends Component { constructor(props) { super(props); } render() { return ( <section className="counter"> <button onClick={() => this.props.add(this.props.counter.count)}>+</button> <span>count is: {this.props.counter.count}</span> <button onClick={() => this.props.reduce(this.props.counter.count)}>-</button> </section> ); } } export default connect(mapStateToProps, mapDispatchToProps)(Index);
建立actions/counter.js
antd
export const ADD = 'add'; export function add(params) { return { type: ADD, params }; } export const REDUCE = 'reduce'; export function reduce(params) { return { type: REDUCE, params }; }
而后新建reducers/counter.js
数据结构
import { fromJS } from 'immutable'; import { createReducer } from 'redux-immutablejs'; import { ADD, REDUCE } from './../actions/counter'; const initialState = fromJS({ count: 0 }); export default createReducer(initialState, { [ADD]: (state, { params }) => { return state.set('count', params + 1); }, [REDUCE]: (state, { params }) => { return state.set('count', params - 1); } });
而后在reducers/rootReducers.js
中引入
// reducers配置文件 import { routerReducer } from 'react-router-redux'; import orderList from './orderList'; import counter from './counter'; // 保存当前正在执行的action type const combineReducers = (reducers) => { return (state = {}, action) => { return Object.keys(reducers).reduce((nextState, key) => { nextState[key] = reducers[key](state[key], action); return nextState; }, { actionType: action.type }); }; }; const rootReducers = combineReducers({ counter, orderList, router: routerReducer }); export default rootReducers;
完成开发而且在开发环境验证以后,就须要部署给咱们的用户了。先执行下面的命令:
$ npm run build
几秒后,输出如下内容:
build
命令会打包全部的资源,包含 JavaScript, CSS, web fonts, images, html 等。而后你能够在 dist/
目录下找到这些文件。