@@ -58,8 +58,7 @@ snippets:
58
58
- ` addPlugin `
59
59
- ` findRule `
60
60
- ` addBabelPlugins `
61
- - ` addLoader `
62
- - ` addExclude `
61
+ - ` addRule `
63
62
64
63
## Example
65
64
Before use examples you should know what happen inside react-scripts webpack config.
@@ -77,6 +76,8 @@ module.exports = function (webpackConfig, isDevelopment) {
77
76
};
78
77
```
79
78
79
+ Also you can find complete examples at [ monkey-react-scripts-example] repo
80
+
80
81
### Webpack Visualizer
81
82
I love visualization so I add [ webpack-visualizer-plugin] [ webpack-visualizer ] to my project
82
83
- install plugin:
@@ -131,18 +132,27 @@ function addBabelPlugins(webpackConfig, plugins) {
131
132
}
132
133
133
134
module .exports = function (webpackConfig , isDevelopment ) {
134
- addBabelPlugins (webpackConfig, [
135
- require .resolve (' babel-plugin-transform-decorators-legacy' )
136
- ]);
135
+ addBabelPlugins (webpackConfig, [' transform-decorators-legacy' ]);
137
136
};
138
137
```
139
138
related issues: [ #107 ] [ 107 ] , [ #167 ] [ 167 ] , [ #214 ] [ 214 ] , [ #309 ] [ 309 ] , [ #411 ] [ 411 ] , [ #1357 ] [ 1357 ]
140
139
141
140
### Relay support
141
+ - install ` babel-plugin-relay `
142
+ ```
143
+ yarn add --dev babel-plugin-relay
144
+ ```
145
+
146
+ - edit ` webpack.monkey.js `
147
+ ``` js
142
148
143
- TODO
149
+ module .exports = function (webpackConfig , isDevelopment ) {
150
+ addBabelPlugins (webpackConfig, [' relay' ]);
151
+ };
152
+ ```
153
+ and continue [ relay documentation] [ relay-setup ] steps.
144
154
145
- you can find support for relay classic in [ old readme] [ old-relay-support ] and get some ideas
155
+ if you are using relay classic you can see [ old readme] [ old-relay-support ] and get some ideas.
146
156
147
157
related issues: [ #462 ] [ 462 ] , [ #662 ] [ 662 ] , [ #900 ] [ 900 ]
148
158
@@ -155,21 +165,27 @@ npm install --save-dev node-sass sass-loader
155
165
156
166
- edit ` webpack.monkey.js ` like this:
157
167
``` js
158
- /* copy addExclude, findRule, addRule from snippets */
168
+ /* copy findRule, addRule from snippets */
159
169
module .exports = function (webpackConfig , isDevelopment ) {
160
- const cssRule = findRule (webpackConfig, (rule ) => {
161
- return (' ' + rule .test === ' ' + / \. css$ / )
162
- });
163
- const cssLoaders = isDevelopment ? cssRule .use : cssRule .loader ;
164
- cssLoaders[cssLoaders .length - 1 ].options .sourceMap = true ; // add source option to postcss
165
- const sassLoader = {loader: require .resolve (' sass-loader' ), options: {sourceMap: true }};
166
- const sassLoaders = cssLoaders .concat (sassLoader);
167
- const sassRule = {
168
- test: / \. scss$ / ,
169
- [isDevelopment ? ' use' : ' loader' ]: sassLoaders
170
- };
171
- addExclude (webpackConfig, / \. scss$ / );
172
- addRule (webpackConfig, sassRule)
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)
173
189
};
174
190
```
175
191
similar code for less or stylus.
@@ -179,27 +195,18 @@ related issues: [#78][78], [#115][115], [#351][351], [#412][412], [#1509][1509],
179
195
## postcss config
180
196
If you want change postcss config you can use this code.
181
197
``` js
182
- module .exports = function (webpackConfig , isDevelopment ) {
183
- const cssRule = findRule (webpackConfig, (rule ) => {
184
- return (' ' + rule .test === ' ' + / \. css$ / )
185
- });
186
- const loaders = isDevelopment ? cssRule .use : cssRule .loader ;
187
- const postcssLoader = loaders[loaders .length - 1 ];
188
- const postcssFunc = postcssLoader .options .plugins ;
189
- postcssLoader .options .plugins = () => {
190
- return [
191
- require (' postcss-inline-rtl' ), // add new postcss plugin
192
- ... postcssFunc () // keep cra postcss plugins
193
- ]
194
- };
195
- };
198
+ // add rtl css support
199
+ const postCssFunction = postCssLoader .options .plugins
200
+ postCssLoader .options .plugins = () => {
201
+ return [... postCssFunction (), require (' postcss-inline-rtl' )]
202
+ }
196
203
```
197
204
198
205
## TODOs
199
206
200
207
- [ ] customize test runner (jest)
201
- - [ ] add more example
202
- - [ ] relay support
208
+ - [x ] add more example
209
+ - [x ] relay support
203
210
204
211
## compatibility
205
212
@@ -216,6 +223,8 @@ module.exports = function (webpackConfig, isDevelopment) {
216
223
[ webpack-visualizer ] : https://github.com/chrisbateman/webpack-visualizer
217
224
[ configurable-react-scripts ] : https://github.com/svrcekmichal/configurable-react-scripts
218
225
[ custom-react-scripts ] : https://github.com/kitze/custom-react-scripts
226
+ [ relay-setup ] : https://facebook.github.io/relay/docs/en/installation-and-setup.html
227
+ [ monkey-react-scripts-example ] : https://github.com/monkey-patches/monkey-react-scripts-example
219
228
[ old-relay-support ] : https://github.com/monkey-patches/monkey-react-scripts/blob/b7380bbb873d637cdd6cf911de9f696b90b608fe/README.md#relay-support
220
229
221
230
[ 107 ] : https://github.com/facebookincubator/create-react-app/issues/107
0 commit comments