想要快速开始 react 多页面应用?css
项目结构如何更合理?node
想要快速上手 Mobx?react
想要快速使用 TypeScript?webpack
想要一键使用 Ant-Design 并能快速自定义主题样式?git
能够的!!!github
这里,受 Vue-cli 和 create-react-app 的启发,我作了这样一个 react 的脚手架 handy-cli,让你一键搭建项目,快速开始。web
使用npm安装: npm install handy-cli -g 使用yarn安装 yarn global add handy-cli
handy create <new-app> cd <new-app> npm run start
运行handy create you-app-name
(例如选择了 ant-design、eslint、mobx),handy-cli 会生成以下项目结构npm
├── node_modules ├── public ├── modifyVars.json ├── package.json ├── readme.md ├── .eslintrc ├── .gitignore └── src ├── components │ ├── ResultItem │ │ └── ResultItem.js │ └── Scroll │ └── Scroll.js ├── modules │ └── mobxGitSearch │ ├── components │ │ ├── ResultList │ │ │ └── ResultList.js │ │ └── Search │ │ └── Search.js │ └── index.js ├── pages │ └── index │ ├── index.js │ └── routes.js ├── stores │ └── SearchGitStore.js └── utils └── index.js
在 src 目录下,有以下子目录json
上面说的这些目录已经配置在config.resolve.alias
,因此,在代码中不须要指定相对路径了后端
in src/modules/mobxGitSearch/index.js import {shake} from "utils"
not
in src/modules/mobxGitSearch/index.js import {shake} from "../utils"
使用 handy-cli 初始化项目后,src/pages 下只有一个 index 文件夹,也就是是个单页应用,要想添加新的独立的单页面很简单
例如,在 src/pages 下新建 doule12 文件夹
src ├── pages └── index │ ├── index.js │ └── routes.js ├── doule12 │── index.js in src/pages/doule12/index.js. ReactDOM.render( <h1>double 12</h1>, document.getElementById("root"), ); if (module.hot) { module.hot.accept(() => {}); }
重启服务后访问 localhost:3000/doble12 就能够看到新加的页面,而 localhost:3000 是默认的单页面
若是你想修改一些 webpack 的配置,在项目根目录,确认代码已经 commit 后,能够执行handy eject
来导出 webpack 的相关配置
支持 Tslint 和 Eslint
若是在建立项目时选择了使用 Typescript,代码校验就只提供 Tslint,要是没选 TypeScript,就提供 Eslint 供选择,Eslint 相关的提供了eslint with airbnb config 和 eslint with prettier config,推荐使用 airbnb config
要想修改一些校验规则,能够修改项目根目录下的.eslintrc 或者 tslint.json
能够选择在代码保存或者提交代码的时候校验,为了代码更快的编译,在提交时校验比较好。提交代码校验的相关配置在 package.json 中
"husky": { "hooks": { "pre-commit": "lint-staged" } }, "lint-staged": { "linters": { "*.{js,jsx}": [ "eslint --fix", "git add" ] }, "ignore": [ "**/build/**.js" ] }
可供选择的状态管理方式
handy-cli 提供了 ant-design 的按需使用加载,建立项目时选择了 ant-design 后能够零配置的直接使用
+ import { Pagination } from "antd"; + <Pagination total={100} /> <Search />
若是选择了使用 ant-design,在项目根目录下会有个 modifyVar.json 文件,在这里定义的那些 less 样式变量,均可以在 modifyVar.json 中赋予新值,保存后,不用重启服务,自动会重启,页面样式就变了
支持 less,sass,stylus and css modules
注意: 如何想使用 css modules,样式文件要以 .module.css 、 .module.less、 .module.sass、.module.styl
做为后缀
开发时要代理到后端服务,在 package.json 中新增 proxy 字段,以下
"proxy": "http://localhost:4000", or proxy: { '/api': { target: '<url>', pathRewrite:{ 'api':'' }, changeOrigin: true }, '/foo': { target: '<other_url>' } }
see more proxy options
欢迎试用,提 BUG