@@ -42,7 +42,7 @@ module.exports = function (webpackConfig, isDevelopment) {
42
42
"scripts": {
43
43
"start": "monkey-react-scripts start",
44
44
"build": "monkey-react-scripts build",
45
- "test": "monkey-react-scripts test --env=jsdom "
45
+ "test": "monkey-react-scripts test"
46
46
}
47
47
```
48
48
@@ -52,13 +52,12 @@ I suggest you see [scripts](scripts) and [bin](bin) folders. (less than 100 line
52
52
Note: returned value of ` require ` function is mutable. so you can mutate that before real build/start script.
53
53
54
54
## Snippets
55
- You can use [ snippets] ( snippets/cra-1 .x.x.md ) if you want.
55
+ You can use [ snippets] ( snippets/cra-2 .x.x.md ) if you want.
56
56
57
57
snippets:
58
58
- ` addPlugin `
59
59
- ` findRule `
60
60
- ` addBabelPlugins `
61
- - ` addRule `
62
61
63
62
## Example
64
63
Before use examples, you should know what happens inside react-scripts webpack config.
@@ -106,33 +105,28 @@ build
106
105
├── index.html
107
106
├── static
108
107
│ ├── css
109
- │ │ ├── main.9a0fe4f1.css
110
- │ │ └── main.9a0fe4f1.css.map
111
108
│ ├── js
112
- │ │ ├── main.373f9afc.js
113
- │ │ └── main.373f9afc.js.map
114
109
│ └── media
115
- │ └── logo.5d5d9eef.svg
116
110
└── stats.html <-- new file
117
111
```
118
112
### Decorator support
119
113
If you love decorators, you can add decorator support:
120
114
- install decorator plugin
121
115
```
122
- npm install --save-dev babel- plugin-transform -decorators-legacy
116
+ npm install --save-dev @ babel/ plugin-proposal -decorators
123
117
```
124
- - edit ` webpack.monkey.js ` like this (copy ` findRule ` , ` addBabelPlugins ` from [ snippets] ( snippets/cra-1 .x.x.md ) ):
118
+ - edit ` webpack.monkey.js ` like this (copy ` findRule ` , ` addBabelPlugins ` from [ snippets] ( snippets/cra-2 .x.x.md ) ):
125
119
``` js
126
120
function findRule (webpackConfig , callback ) {
127
121
/* snippet codes */
128
122
}
129
123
130
124
function addBabelPlugins (webpackConfig , plugins ) {
131
- /* snippet codes */
125
+ /* snippet codes */
132
126
}
133
127
134
128
module .exports = function (webpackConfig , isDevelopment ) {
135
- addBabelPlugins (webpackConfig, [' transform-decorators- legacy' ]);
129
+ addBabelPlugins (webpackConfig, [[ " @babel/plugin-proposal-decorators " , { legacy: true }] ]);
136
130
};
137
131
```
138
132
related issues: [ #107 ] [ 107 ] , [ #167 ] [ 167 ] , [ #214 ] [ 214 ] , [ #309 ] [ 309 ] , [ #411 ] [ 411 ] , [ #1357 ] [ 1357 ]
@@ -156,52 +150,17 @@ if you are using relay classic you can see [old readme][old-relay-support] and g
156
150
157
151
related issues: [ #462 ] [ 462 ] , [ #662 ] [ 662 ] , [ #900 ] [ 900 ]
158
152
159
- ### scss support
160
- - install ` node-sass ` and ` sass-loader ` :
161
-
162
- ```
163
- npm install --save-dev node-sass sass-loader
164
- ```
165
-
166
- - edit ` webpack.monkey.js ` like this:
167
- ``` js
168
- /* copy findRule, addRule from snippets */
169
- module .exports = function (webpackConfig , isDevelopment ) {
170
- // find css rule
171
- const cssRule = findRule (webpackConfig, (rule ) => {
172
- return (' ' + rule .test === ' ' + / \. css$ / )
173
- });
174
- const cssLoaders = isDevelopment ? cssRule .use : cssRule .loader ;
175
-
176
- const postCssLoader = cssLoaders[cssLoaders .length - 1 ];
177
- postCssLoader .options .sourceMap = true ; // add source option to postcss
178
-
179
- // add sass support
180
- const sassLoader = {loader: require .resolve (' sass-loader' ), options: {sourceMap: true }};
181
- const sassLoaders = cssLoaders .concat (sassLoader);
182
-
183
- const sassRule = {
184
- test: / \. scss$ / ,
185
- [isDevelopment ? ' use' : ' loader' ]: sassLoaders,
186
- };
187
-
188
- addRule (webpackConfig, sassRule)
189
- };
190
- ```
191
- similar code for less or stylus.
192
-
193
- related issues: [ #78 ] [ 78 ] , [ #115 ] [ 115 ] , [ #351 ] [ 351 ] , [ #412 ] [ 412 ] , [ #1509 ] [ 1509 ] , [ #1639 ] [ 1639 ]
194
-
195
153
## postcss config
196
154
If you want to change postcss config you can use this code.
197
155
``` js
198
156
// add rtl css support
157
+ // find postCssLoader
199
158
const postCssFunction = postCssLoader .options .plugins
200
159
postCssLoader .options .plugins = () => {
201
160
return [... postCssFunction (), require (' postcss-inline-rtl' )]
202
161
}
203
162
```
204
-
163
+ you can find more detail in [ this file ] [ css-patch ]
205
164
## TODOs
206
165
207
166
- [ ] customize test runner (jest)
@@ -227,6 +186,7 @@ If you want to change postcss config you can use this code.
227
186
[ relay-setup ] : https://facebook.github.io/relay/docs/en/installation-and-setup.html
228
187
[ monkey-react-scripts-example ] : https://github.com/monkey-patches/monkey-react-scripts-example
229
188
[ old-relay-support ] : https://github.com/monkey-patches/monkey-react-scripts/blob/b7380bbb873d637cdd6cf911de9f696b90b608fe/README.md#relay-support
189
+ [ css-patch ] : https://github.com/monkey-patches/monkey-react-scripts-example/blob/d759030325ca2d638b1ea0dd44e51655b88d5022/webpack-helpers/cssPatch.js
230
190
231
191
[ 107 ] : https://github.com/facebookincubator/create-react-app/issues/107
232
192
[ 167 ] : https://github.com/facebookincubator/create-react-app/issues/167
@@ -238,10 +198,3 @@ If you want to change postcss config you can use this code.
238
198
[ 462 ] : https://github.com/facebookincubator/create-react-app/issues/462
239
199
[ 662 ] : https://github.com/facebookincubator/create-react-app/pull/662
240
200
[ 900 ] : https://github.com/facebookincubator/create-react-app/issues/900
241
-
242
- [ 78 ] : https://github.com/facebookincubator/create-react-app/issues/78
243
- [ 115 ] : https://github.com/facebookincubator/create-react-app/pull/115
244
- [ 351 ] : https://github.com/facebookincubator/create-react-app/issues/351
245
- [ 412 ] : https://github.com/facebookincubator/create-react-app/pull/412
246
- [ 1509 ] : https://github.com/facebookincubator/create-react-app/pull/1509
247
- [ 1639 ] : https://github.com/facebookincubator/create-react-app/issues/1639
0 commit comments