1 | # react-beaker ![build status](https://travis-ci.org/wizawu/react-beaker.svg)
|
2 |
|
3 | A devtool built on webpack for cutting down heavy dependencies/devDependencies of [React](https://facebook.github.io/react/) projects.
|
4 |
|
5 | For example, in many cases, you may need a `package.json` like
|
6 |
|
7 | ```javascript
|
8 | {
|
9 | "scripts": {
|
10 | "build": "...",
|
11 | "start": "...",
|
12 | "watch": "...",
|
13 | "publish": "...",
|
14 | ...
|
15 | },
|
16 | "dependencies": {
|
17 | "react": "...",
|
18 | "react-dom": "...",
|
19 | "react-router": "...",
|
20 | "redux": "...",
|
21 | ...
|
22 | "other-libs": "..."
|
23 | },
|
24 | "devDependencies": {
|
25 | "webpack": "...",
|
26 | "many-webpack-plugins": "...",
|
27 | "babel": "...",
|
28 | "many-babel-plugins": "...",
|
29 | "uglifyjs": "...",
|
30 | ...
|
31 | }
|
32 | }
|
33 | ```
|
34 |
|
35 | With `react-beaker`, you can simply write
|
36 |
|
37 | ```javascript
|
38 | {
|
39 | "dependencies": {
|
40 | "other-libs": "..."
|
41 | }
|
42 | }
|
43 | ```
|
44 |
|
45 | ### Installation
|
46 |
|
47 | It is recommended to install `react-beaker` globally.
|
48 |
|
49 | ```shell
|
50 | npm install -g react-beaker
|
51 | ```
|
52 |
|
53 | ### Usage
|
54 |
|
55 | 1. Project structure (or the frontend part) should be as follow.
|
56 |
|
57 | ```shell
|
58 | path/to/source
|
59 | +-- html
|
60 | +-- js
|
61 | | +-- entries
|
62 | +-- package.json (optional)
|
63 | ```
|
64 |
|
65 | 2. Commands
|
66 |
|
67 | ```shell
|
68 | # If there is package.json in the source directory, you need to run `npm install` first
|
69 |
|
70 | react-beaker watch path/to/source
|
71 | react-beaker build path/to/source
|
72 | react-beaker publish path/to/source
|
73 | ```
|
74 |
|
75 | For `watch` and `publish`, all source files with extensions `.js`, `.jsx`, `.ts` or `.tsx` will be output with extension `.min.js` to `dist`.
|
76 |
|
77 | ```shell
|
78 | path/to/source
|
79 | +-- js
|
80 | | +-- entries
|
81 | | +-- a.js
|
82 | | +-- b.jsx
|
83 | +-- dist
|
84 | +-- a.min.js
|
85 | +-- b.min.js
|
86 | ```
|
87 |
|
88 | For `build`, the extension would be `.js`.
|
89 |
|
90 | ```shell
|
91 | path/to/source
|
92 | +-- js
|
93 | | +-- entries
|
94 | | +-- a.js
|
95 | | +-- b.jsx
|
96 | +-- dist
|
97 | +-- a.js
|
98 | +-- b.js
|
99 | ```
|
100 |
|
101 | Meanwhile, HTML source files will also be compiled to `dist`.
|
102 |
|
103 | ```shell
|
104 | path/to/source
|
105 | +-- html
|
106 | | +-- app.html
|
107 | +-- dist
|
108 | +-- app.html
|
109 | ```
|
110 |
|
111 | 3. Options
|
112 |
|
113 | |Option|Explanation|Type|
|
114 | |---|---|---|
|
115 | |`--hash, -h`| include chunkhash in output filename | boolean
|
116 | |`--tsconfig, -c` | specify a tsconfig.json file, instead of using the default one (generated by react-beaker) | string
|
117 | |`--publicPath, -p` | specity a customized publicPath (can be access by o.webpack.publicPath later) | string
|
118 | |`--reactToolkit, -t`| build and include reactToolkit in output folder | boolean
|
119 | |`--strict, -s`| Set tsconfig.strict to `true` | boolean
|
120 |
|
121 | #### `--hash, -c`
|
122 |
|
123 | Given the `--hash` flag is provided, react-beaker will include chunkhash in output filename:
|
124 |
|
125 | ```html
|
126 | <script src="//public/dist/{%= o.webpack.assetsByChunkName.index %}"></script>
|
127 | ```
|
128 | and you run `react-beaker publish . -c`, the output HTML will include a reference to the assets with chunkhash:
|
129 |
|
130 | ```html
|
131 | <script src="/public/dist/a.82d503654d047fcf5145.min.js"></script>
|
132 | ```
|
133 | And the project directory will looks like this:
|
134 |
|
135 | ```
|
136 | path/to/source
|
137 | +-- js
|
138 | | +-- entries
|
139 | | +-- index.js
|
140 | | +-- a.jsx
|
141 | +-- dist
|
142 | +-- index.88483fa4cece1dc223d5.min.js
|
143 | +-- a.82d503654d047fcf5145.min.js
|
144 | ```
|
145 |
|
146 | ### Advanced
|
147 |
|
148 | #### React Stuff
|
149 |
|
150 | You will find `react-toolkit.min.js` in `dist`, which should be included in your HTML.
|
151 |
|
152 | ```html
|
153 | <script src="./react-toolkit.min.js"></script>
|
154 | ```
|
155 |
|
156 | Then you are able to import the following React libraries without adding them to `package.json`.
|
157 |
|
158 | ```javascript
|
159 | import React from "react";
|
160 | import ReactDOM from "react-dom";
|
161 | import Redux from "redux";
|
162 | import { IndexRoute, Route, Router } from "react-router";
|
163 | ```
|
164 |
|
165 | #### Source Map
|
166 |
|
167 | Source map is enabled when using `react-beaker watch`.
|
168 |
|
169 | #### CSS and Less
|
170 |
|
171 | ```javascript
|
172 | import "../css/default.css";
|
173 | import "../css/theme.less";
|
174 | ```
|