Skip to content

Commit 300d246

Browse files
committed
add "enable .babelrc" section to readme
1 parent 3020fcf commit 300d246

File tree

2 files changed

+34
-23
lines changed

2 files changed

+34
-23
lines changed

README.md

+31-20
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,7 @@ snippets:
6666

6767
- `addPlugin`
6868
- `findRule`
69-
- `addBabelPlugins`
69+
- `findBabelRule`
7070

7171
## Example
7272

@@ -87,6 +87,27 @@ module.exports = function(webpackConfig, isDevelopment) {
8787

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

90+
### Enable `.babelrc`
91+
92+
The `.babelrc` file is enabled for tests if you have `webpack.monkey.js` file. also, you can enable `.babelrc` for build and start:
93+
94+
- edit `webpack.monkey.js` like this (copy `findRule`, `findBabelRule` from [snippets](snippets/cra-2.x.x.md)):
95+
96+
```js
97+
function findRule(webpackConfig, callback) {
98+
/* snippet codes */
99+
}
100+
101+
function findBabelRule(webpackConfig, callback) {
102+
/* snippet codes */
103+
}
104+
105+
module.exports = function(webpackConfig, isDevelopment) {
106+
const babelRule = findBabelRule(webpackConfig);
107+
babelRule.options.babelrc = true;
108+
};
109+
```
110+
90111
### Webpack Visualizer
91112

92113
I love visualization so, I add [webpack-visualizer-plugin][webpack-visualizer] to my project
@@ -137,22 +158,12 @@ If you love decorators, you can add decorator support:
137158
npm install --save-dev @babel/plugin-proposal-decorators
138159
```
139160

140-
- edit `webpack.monkey.js` like this (copy `findRule`, `addBabelPlugins` from [snippets](snippets/cra-2.x.x.md)):
161+
- edit `.babelrc` like this:
141162

142-
```js
143-
function findRule(webpackConfig, callback) {
144-
/* snippet codes */
145-
}
146-
147-
function addBabelPlugins(webpackConfig, plugins) {
148-
/* snippet codes */
163+
```json
164+
{
165+
"plugins": [["@babel/plugin-proposal-decorators", { "legacy": true }]]
149166
}
150-
151-
module.exports = function(webpackConfig, isDevelopment) {
152-
addBabelPlugins(webpackConfig, [
153-
["@babel/plugin-proposal-decorators", { legacy: true }]
154-
]);
155-
};
156167
```
157168

158169
related issues: [#107][107], [#167][167], [#214][214], [#309][309], [#411][411], [#1357][1357]
@@ -165,12 +176,12 @@ related issues: [#107][107], [#167][167], [#214][214], [#309][309], [#411][411],
165176
yarn add --dev babel-plugin-relay
166177
```
167178

168-
- edit `webpack.monkey.js`
179+
- edit `.babelrc` like this:
169180

170-
```js
171-
module.exports = function(webpackConfig, isDevelopment) {
172-
addBabelPlugins(webpackConfig, ["relay"]);
173-
};
181+
```json
182+
{
183+
"plugins": ["relay"]
184+
}
174185
```
175186

176187
and continue [relay documentation][relay-setup] steps.

snippets/cra-2.x.x.md

+3-3
Original file line numberDiff line numberDiff line change
@@ -22,14 +22,14 @@ function findRule(webpackConfig, callback) {
2222
}
2323
```
2424

25-
## Add Babel plugin
25+
## find Babel rule
2626
requirement: `findRule`
2727
```js
28-
function addBabelPlugins(webpackConfig, plugins) {
28+
function findBabelRule(webpackConfig, plugins) {
2929
// find babel rule
3030
const babelRule = findRule(webpackConfig, (rule) => {
3131
return ('' + rule.test === '' + /\.(js|jsx)$/)
3232
});
33-
babelRule.options.plugins = (babelRule.options.plugins || []).concat(plugins);
33+
return babelRule;
3434
}
3535
```

0 commit comments

Comments
 (0)