Skip to content

Commit 3020fcf

Browse files
committed
reformat readme
1 parent 2813f0b commit 3020fcf

File tree

1 file changed

+64
-34
lines changed

1 file changed

+64
-34
lines changed

README.md

+64-34
Original file line numberDiff line numberDiff line change
@@ -1,22 +1,26 @@
11
# monkey-react-scripts
2+
23
Monkey react script runner: Customize react-scripts webpack config without eject or fork
34

45
Many of you want to add a small change to your webpack config created by create-react-app. but you don't want to eject. or
5-
use other scripts like [configurable-react-scripts][configurable-react-scripts] or
6+
use other scripts like [configurable-react-scripts][configurable-react-scripts] or
67
[custom-react-scripts][custom-react-scripts] because of update delay.
7-
8+
89
With monkey-react-scripts you can use react-scripts configs, but monkey patched one. so you always have updated
910
react-scripts.
1011

1112
## ☢ DANGER ☢
1213

13-
> As [@gaearon](https://github.com/gaearon) mentioned multiple times there, it's not good idea to extend it. From my
14-
point of view, I'm giving you gun, so try not to shot yourself, because probably nobody will help you. When you modify
15-
something, be completely sure what you doing!
14+
> As [@gaearon](https://github.com/gaearon) mentioned multiple times there, it's not good idea to extend it. From my
15+
> point of view, I'm giving you gun, so try not to shot yourself, because probably nobody will help you. When you modify
16+
> something, be completely sure what you doing!
1617
1718
[source][configurable-react-scripts]
19+
1820
## Usage
21+
1922
- use create-react-app and create your project, [more detail][create-react-app]
23+
2024
```
2125
npm install -g create-react-app
2226
@@ -31,13 +35,15 @@ npm install monkey-react-scripts --save-dev --save-exact
3135
```
3236

3337
- create `webpack.monkey.js` in the root of your project. you can modify webpack config here.
38+
3439
```js
35-
module.exports = function (webpackConfig, isDevelopment) {
36-
// mutate webpackConfig
40+
module.exports = function(webpackConfig, isDevelopment) {
41+
// mutate webpackConfig
3742
};
3843
```
3944

4045
- edit `package.json` and replace scripts
46+
4147
```
4248
"scripts": {
4349
"start": "monkey-react-scripts start",
@@ -47,21 +53,25 @@ module.exports = function (webpackConfig, isDevelopment) {
4753
```
4854

4955
## How it works
56+
5057
I suggest you see [scripts](scripts) and [bin](bin) folders. (less than 100 line of code)
5158

5259
Note: returned value of `require` function is mutable. so you can mutate that before real build/start script.
5360

5461
## Snippets
62+
5563
You can use [snippets](snippets/cra-2.x.x.md) if you want.
5664

5765
snippets:
66+
5867
- `addPlugin`
5968
- `findRule`
6069
- `addBabelPlugins`
6170

6271
## Example
72+
6373
Before use examples, you should know what happens inside react-scripts webpack config.
64-
first, see and read this files:
74+
first, see and read this files:
6575

6676
- `node_modules/react-scripts/config/webpack.config.dev.js`
6777
- `node_modules/react-scripts/config/webpack.config.prod.js`
@@ -70,31 +80,38 @@ also, you can log `webpackConfig` value.
7080

7181
```js
7282
// webpack.monkey.js
73-
module.exports = function (webpackConfig, isDevelopment) {
74-
console.log(webpackConfig)
83+
module.exports = function(webpackConfig, isDevelopment) {
84+
console.log(webpackConfig);
7585
};
7686
```
7787

7888
Also, you can find complete examples at [monkey-react-scripts-example] repo
7989

8090
### Webpack Visualizer
91+
8192
I love visualization so, I add [webpack-visualizer-plugin][webpack-visualizer] to my project
93+
8294
- install plugin:
95+
8396
```
8497
npm install webpack-visualizer-plugin --save-dev
8598
```
99+
86100
- add the plugin to config (only at build time)
101+
87102
```js
88103
// webpack.monkey.js
89-
var Visualizer = require('webpack-visualizer-plugin');
104+
var Visualizer = require("webpack-visualizer-plugin");
90105

91-
module.exports = function (webpackConfig, isDevelopment) {
92-
if (!isDevelopment) {
93-
webpackConfig.plugins.push(new Visualizer());
94-
}
106+
module.exports = function(webpackConfig, isDevelopment) {
107+
if (!isDevelopment) {
108+
webpackConfig.plugins.push(new Visualizer());
109+
}
95110
};
96111
```
112+
97113
- build
114+
98115
```
99116
$ npm run build
100117
// some output
@@ -109,58 +126,74 @@ build
109126
│   └── media
110127
└── stats.html <-- new file
111128
```
129+
112130
### Decorator support
131+
113132
If you love decorators, you can add decorator support:
133+
114134
- install decorator plugin
135+
115136
```
116137
npm install --save-dev @babel/plugin-proposal-decorators
117138
```
139+
118140
- edit `webpack.monkey.js` like this (copy `findRule`, `addBabelPlugins` from [snippets](snippets/cra-2.x.x.md)):
141+
119142
```js
120143
function findRule(webpackConfig, callback) {
121-
/* snippet codes */
144+
/* snippet codes */
122145
}
123146

124147
function addBabelPlugins(webpackConfig, plugins) {
125-
/* snippet codes */
148+
/* snippet codes */
126149
}
127150

128-
module.exports = function (webpackConfig, isDevelopment) {
129-
addBabelPlugins(webpackConfig, [["@babel/plugin-proposal-decorators", {legacy: true}]]);
151+
module.exports = function(webpackConfig, isDevelopment) {
152+
addBabelPlugins(webpackConfig, [
153+
["@babel/plugin-proposal-decorators", { legacy: true }]
154+
]);
130155
};
131156
```
157+
132158
related issues: [#107][107], [#167][167], [#214][214], [#309][309], [#411][411], [#1357][1357]
133159

134160
### Relay support
161+
135162
- install `babel-plugin-relay`
163+
136164
```
137165
yarn add --dev babel-plugin-relay
138166
```
139167

140168
- edit `webpack.monkey.js`
141-
```js
142169

143-
module.exports = function (webpackConfig, isDevelopment) {
144-
addBabelPlugins(webpackConfig, ['relay']);
170+
```js
171+
module.exports = function(webpackConfig, isDevelopment) {
172+
addBabelPlugins(webpackConfig, ["relay"]);
145173
};
146174
```
175+
147176
and continue [relay documentation][relay-setup] steps.
148177

149178
if you are using relay classic you can see [old readme][old-relay-support] and get some ideas.
150179

151180
related issues: [#462][462], [#662][662], [#900][900]
152-
181+
153182
## postcss config
154-
If you want to change postcss config you can use this code.
183+
184+
If you want to change postcss config you can use this code.
185+
155186
```js
156-
// add rtl css support
157-
// find postCssLoader
158-
const postCssFunction = postCssLoader.options.plugins
159-
postCssLoader.options.plugins = () => {
160-
return [...postCssFunction(), require('postcss-inline-rtl')]
161-
}
187+
// add rtl css support
188+
// find postCssLoader
189+
const postCssFunction = postCssLoader.options.plugins;
190+
postCssLoader.options.plugins = () => {
191+
return [...postCssFunction(), require("postcss-inline-rtl")];
192+
};
162193
```
194+
163195
you can find more detail in [this file][css-patch]
196+
164197
## TODOs
165198

166199
- [ ] customize test runner (jest)
@@ -176,9 +209,8 @@ you can find more detail in [this file][css-patch]
176209
| 2.0.0 - 2.1.1 | 0.1.2 |
177210
| 2.1.2 | 0.1.4 |
178211

179-
180-
181212
## Thanks
213+
182214
@svrcekmichal for [configurable-react-scripts][configurable-react-scripts]
183215

184216
[create-react-app]: https://github.com/facebookincubator/create-react-app#tldr
@@ -189,14 +221,12 @@ you can find more detail in [this file][css-patch]
189221
[monkey-react-scripts-example]: https://github.com/monkey-patches/monkey-react-scripts-example
190222
[old-relay-support]: https://github.com/monkey-patches/monkey-react-scripts/blob/b7380bbb873d637cdd6cf911de9f696b90b608fe/README.md#relay-support
191223
[css-patch]: https://github.com/monkey-patches/monkey-react-scripts-example/blob/d759030325ca2d638b1ea0dd44e51655b88d5022/webpack-helpers/cssPatch.js
192-
193224
[107]: https://github.com/facebookincubator/create-react-app/issues/107
194225
[167]: https://github.com/facebookincubator/create-react-app/issues/167
195226
[214]: https://github.com/facebookincubator/create-react-app/issues/214
196227
[309]: https://github.com/facebookincubator/create-react-app/issues/309
197228
[411]: https://github.com/facebookincubator/create-react-app/issues/411
198229
[1357]: https://github.com/facebookincubator/create-react-app/issues/1357
199-
200230
[462]: https://github.com/facebookincubator/create-react-app/issues/462
201231
[662]: https://github.com/facebookincubator/create-react-app/pull/662
202232
[900]: https://github.com/facebookincubator/create-react-app/issues/900

0 commit comments

Comments
 (0)