Skip to content

Commit

Permalink
支持vue
Browse files Browse the repository at this point in the history
  • Loading branch information
moocss committed Apr 28, 2017
1 parent b8a75ce commit 4c842bb
Show file tree
Hide file tree
Showing 54 changed files with 1,625 additions and 6,986 deletions.
9 changes: 9 additions & 0 deletions .babelrc
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
{
"presets": [
"es2015",
"stage-2"
],
"plugins": [
"transform-runtime"
]
}
10 changes: 10 additions & 0 deletions .editorconfig
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
[*]
indent_style = space
end_of_line = lf
indent_size = 2
charset = utf-8
trim_trailing_whitespace = true

[*.md]
max_line_length = 0
trim_trailing_whitespace = false
1 change: 1 addition & 0 deletions .eslintrc
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
"extends": "standard",
"rules": {
"no-console": [0],
"no-unused-vars": [0],
"indent": [2, 2],
"semi": [2, "never"]
}
Expand Down
3 changes: 0 additions & 3 deletions .vscode/settings.json

This file was deleted.

179 changes: 147 additions & 32 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
# Bee
# bees
A simple CLI for serve and build web app, support JSON pattern config.

一个简单的CLI工具,无需复杂的配置,轻松的构建和调试项目。

### 声明

Bee[create-react-app](https://github.com/facebookincubator/create-react-app)[roadhog](https://github.com/sorrycc/roadhog) 的克隆版,根据团队和自己日常开发的需求修改的一个版本。
bees[create-react-app](https://github.com/facebookincubator/create-react-app)[roadhog](https://github.com/sorrycc/roadhog) 的克隆版,根据团队和自己日常开发的需求修改的一个版本。

### 安装

Expand All @@ -20,18 +20,18 @@ $ npm install -g bees-cli
本地开发

```bash
$ bee server
$ bees server
```

打包发布

```bash
$ bee build
$ bees build
```

### Mock

bee server 支持 mock 功能,类似 [dora-plugin-proxy](https://github.com/dora-js/dora-plugin-proxy),在 `.beerc.mock.js` 中进行配置,支持基于 require 动态分析的实时刷新,支持 ES6 语法,以及友好的出错提示。
bees server 支持 mock 功能,类似 [dora-plugin-proxy](https://github.com/dora-js/dora-plugin-proxy),在 `.beesrc.mock.js` 中进行配置,支持基于 require 动态分析的实时刷新,支持 ES6 语法,以及友好的出错提示。

比如:

Expand All @@ -45,47 +45,60 @@ export default {

// 支持自定义函数,API 参考 express@4
'POST /api/users/create': (req, res) => { res.end('OK'); },

// Forward 到另一个服务器
'GET /assets/*': 'https://assets.online/',

// Forward 到另一个服务器,并指定子路径
// 请求 /someDir/0.0.50/index.css 会被代理到 https://g.alicdn.com/tb-page/taobao-home, 实际返回 https://g.alicdn.com/tb-page/taobao-home/0.0.50/index.css
'GET /someDir/(.*)': 'https://g.alicdn.com/tb-page/taobao-home',
};
```

### 智能重启

配置文件修改的修改会触发 bee server 的自动重启,会触发重启的文件有:
配置文件修改的修改会触发 bees server 的自动重启,会触发重启的文件有:

* `.beerc`
* `.beerc.js`
* `.beerc.mock.js`
* `.beesrc`
* `.beesrc.js`
* `.beesrc.mock.js`

### 配置

关于配置的一些基本概念:

* 配置存于 `.beerc` 文件中(如果你不喜欢 JSON 配置,可以用 `.beerc.js` 以 JS 的方式编写,支持 ES6)
* 配置存于 `.beesrc` 文件中(如果你不喜欢 JSON 配置,可以用 `.beesrc.js` 以 JS 的方式编写,支持 ES6)
* 格式为 `JSON`,允许注释
* 布尔类型的配置项默认值均为 `false`
* 支持通过 `webpack.config.js` 以编码的方式进行配置,但不推荐,因为 bee 本身的 major 或 minor 升级可能会引起兼容问题。使用时会给予警告⚠️⚠️⚠️, 。(`webpack.config.js` 本身的编写支持 ES6,会通过 babal-register 做一层转换。)
* 支持通过 `webpack.config.js` 以编码的方式进行配置,但不推荐,因为 bees 本身的 major 或 minor 升级可能会引起兼容问题。使用时会给予警告⚠️⚠️⚠️, 。(`webpack.config.js` 本身的编写支持 ES6,会通过 babal-register 做一层转换。)

.beerc 默认配置:
.beesrc 默认配置:

```json
{
"use": "react",
"entry": "src/index.js",
"publicPath": "/",
"outputPath": "./dist",
"extraBabelPresets": [],
"extraBabelPlugins": [],
"extraPostCSSPlugins": [],
"disableCSSModules": false,
"cssSourceMap": false,
"analyze": false,
"autoprefixer": null,
"externals": null,
"library": null,
"libraryTarget": "var",
"multipage": false,
"dllPlugin": null,
"define": null,
"proxy": null,
"env": null
"env": null,
}
```

.beerc 的 React开发配置:
.beesrc 的 React开发配置:

```json
{
Expand All @@ -95,7 +108,7 @@ export default {
"react"
],
"extraBabelPlugins": [
"transform-runtime"
"react-require"
],
"autoprefixer": null,
"externals": null,
Expand All @@ -118,8 +131,41 @@ package.json 的 React开发配置:

```json
{
"babel-preset-react": "",
"babel-plugin-transform-runtime": ""
"babel-preset-react": ""
}
```

.beesrc 的 Vue开发配置:

```json
{
"entry": "src/index.js",
"publicPath": "/",
"extraBabelPlugins": [
"transform-vue-jsx"
],
"autoprefixer": null,
"externals": null,
"multipage": true,
"define": null,
"proxy": null,
"env": {
"development": {
"cssSourceMap": false
},
"production": {
"cssSourceMap": true,
"analyze": true
}
}
}
```

package.json 的 Vue开发配置:

```json
{
"babel-plugin-transform-vue-jsx": ""
}
```

Expand All @@ -133,6 +179,10 @@ package.json 的 React开发配置:
"entry": "src/pages/*.js"
```

### disableCSSModules

禁用 [CSS Modules](https://github.com/css-modules/css-modules)。最好别关,熟悉并使用他后,你会发现写样式简单了很多。

### publicPath

配置生产环境的 [publicPath](http://webpack.github.io/docs/configuration.html#output-publicpath),开发环境下永远为 `/`
Expand All @@ -141,6 +191,36 @@ package.json 的 React开发配置:

配置额外的 babel plugin。babel plugin 只能添加,不允许覆盖和删除。

```
"extraBabelPlugins": ["transform-runtime"],
"env": {
"development": {
"extraBabelPlugins": ["dva-hmr"]
}
}
```

这样,开发环境下的 extraBabelPlugins 是 `["transform-runtime", "dva-hmr"]`,而生产环境下是 `["transform-runtime"]`


### extraPostCSSPlugins

配置额外的 postcss 插件。

注意:由于 postcss 的插件是以函数的方式进行配置的,所以这个配置只能在 `.beesrc.js` 里使用。

比如:

```
import pxtorem from 'postcss-pxtorem'
extraPostCSSPlugins: [
pxtorem({
rootValue: 100,
propWhiteList: [],
}),
],
```

### autoprefixer

配置 autoprefixer 参数,详见 [autoprefixer](https://github.com/postcss/autoprefixer)[browserslist](https://github.com/ai/browserslist#queries)
Expand Down Expand Up @@ -176,13 +256,43 @@ package.json 的 React开发配置:
如果要做数据 mock,可以考虑和 [json-server](https://github.com/typicode/json-server) 或者 [mock-server](https://github.com/thoughtbit/mock-server) 结合使用,把 `/api` 代理到 json-server 或者 mock-server 启动的端口。

### externals

```
{
"externals": {
"react": "window.React"
}
}
```
配置 webpack 的 [externals](http://webpack.github.io/docs/configuration.html#externals) 属性。

### library

配置 webpack 的 [library](http://webpack.github.io/docs/configuration.html#output-library) 属性。

### libraryTarget

配置 webpack 的 [libraryTarget](http://webpack.github.io/docs/configuration.html#output-librarytarget) 属性。


### multipage

配置是否多页应用。多页应用会自动提取公共部分为 common.js 和 common.css 。

### dllPlugin
```
"dllPlugin": {
"name": "bees",
"include": [
"react",
"react-dom",
"react-redux",
"react-router",
"react-router-redux",
"redux"
]
}
```

### define

配置 webpack 的 [DefinePlugin](http://webpack.github.io/docs/list-of-plugins.html#defineplugin) 插件,define 的值会自动做 `JSON.stringify` 处理。
Expand Down Expand Up @@ -223,38 +333,38 @@ package.json 的 React开发配置:

可环境变量临时配置一些参数,包括:

- `PORT`, 端口号,默认 8000
- `PORT`, 端口号,默认 12306
- `HOST`, 默认 localhost
- `HTTPS`,是否开启 https,默认关闭

比如,使用 12306 端口开启服务器可以这样:

```bash
// OS X, Linux
$ PORT=12306 bee server
$ PORT=12306 bees server

// Windows (cmd.exe)
$ set PORT=12306&&bee server
$ set PORT=12306&&bees server
```

## 命令行参数

### bee server
### bees server

```bash
$ bee server -h
Usage: bee server [options]
$ bees server -h
Usage: bees server [options]

Options:
--open Open url in browser after started [boolean] [default: true]
-h Show help [boolean]
```

### bee build
### bees build

```bash
$ bee build -h
Usage: bee build [options]
$ bees build -h
Usage: bees build [options]

Options:
--debug Build without compress [boolean] [default: false]
Expand All @@ -264,11 +374,11 @@ Options:
-h Show help [boolean]
```

### bee test
### bees test

```bash
$ bee test -h
Usage: bee test [options] [mocha-options]
$ bees test -h
Usage: bees test [options] [mocha-options]

Options:
--coverage Output coverage [boolean] [default: false]
Expand All @@ -279,7 +389,12 @@ Options:
我们约定 `public` 目录下的文件会在 server 和 build 时被自动 copy 到输出目录(默认是 `./dist`)下。所以可以在这里存放 favicon, iconfont, html, html 里引用的图片等。

## 常见问题
node-sass 安装失败

### 那么为什么提供 JSON 级别的约定型配置,而非类似 webpack.config.js 的编码型配置?

首先是 JSON 的方式比较简单,`true`/`false` 或是一些简单的字符串就可完成配置;另外,JSON 方式能有效控制使用场景,而编程式的非常不可控,roadhog 的一个简单改动都可能导致之前的配置不可用。

### node-sass 安装失败
```bash
SASS_BINARY_SITE=https://npm.taobao.org/mirrors/node-sass/ npm install node-sass --save-dev
```
```
7 changes: 4 additions & 3 deletions bin/bee → bin/bees
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,9 @@ var major = versions[0]
var minor = versions[1]
var platform = os.platform()

if (((major * 10) + (minor * 1)) < 69) {
console.log(chalk.red(`Node version (${major}.${minor}) is not compatibile, ${chalk.cyan('must >= 6.9')}.`))
console.log(chalk.red(`你的 Node 版本是 ${chalk.yellow(`${major}.${minor}`)},请升级到${chalk.cyan(' 6.9 或以上')}.`))
if (((major * 10) + (minor * 1)) < 65) {
console.log(chalk.red(`Node version (${major}.${minor}) is not compatibile, ${chalk.cyan('must >= 6.5')}.`))
console.log(chalk.red(`你的 Node 版本是 ${chalk.yellow(`${major}.${minor}`)},请升级到${chalk.cyan(' 6.5 或以上')}.`))
console.log()
if (platform === 'darwin') {
console.log(`推荐用 ${chalk.cyan('https://github.com/creationix/nvm')} 管理和升级你的 node 版本。`)
Expand All @@ -33,6 +33,7 @@ case '--version':
console.log(require('../package.json').version)
break
case 'build':
case 'build-dll':
case 'server':
case 'test':
result = spawn.sync(
Expand Down
Loading

0 comments on commit 4c842bb

Please sign in to comment.