Skip to content

Commit 7a5b69e

Browse files
committed
add snippets
1 parent 56c90ec commit 7a5b69e

File tree

3 files changed

+55
-3
lines changed

3 files changed

+55
-3
lines changed

README.md

+18-3
Original file line numberDiff line numberDiff line change
@@ -32,9 +32,17 @@ module.exports = function (webpackConfig, isDevelopment) {
3232
}
3333
```
3434

35+
## Snippets
36+
You can use [snippets](snippets/) if you want.
37+
38+
snippets:
39+
- `addPlugin`
40+
- `findLoader`
41+
- `addBabelPlugins`
42+
3543
## Example
3644
### Webpack Visualizer
37-
I love visualization so I wan't add [webpack-visualizer-plugin][webpack-visualizer] to my project
45+
I love visualization so I add [webpack-visualizer-plugin][webpack-visualizer] to my project
3846
- install plugin:
3947
```
4048
npm install webpack-visualizer-plugin --save-dev
@@ -76,7 +84,7 @@ If you love decorators, you can add decorator support:
7684
```
7785
npm install --save-dev babel-plugin-transform-decorators-legacy
7886
```
79-
- edit `webpack.monkey.js` like this:
87+
- edit `webpack.monkey.js` like this (copy `findLoader`, `addBabelPlugins` from [snippets](snippets/cra-0.9.x.md)):
8088
```js
8189
function findLoader(config, callback) {
8290
var index = config.module.loaders.findIndex(callback);
@@ -122,9 +130,16 @@ module.exports = function (webpackConfig, isDevelopment) {
122130
```
123131
related issues: [#462][462], [#662][662], [#900][900]
124132
## TODOs
125-
- [ ] add helpers
133+
- [ ] <del>add helpers</del> snippets
134+
- [x] addPlugin
135+
- [x] findLoader
136+
- [x] addBabelPlugins
137+
- [ ] extract text webpack plugin
138+
- [ ] addExclude
139+
- [ ] addLoader
126140
- [ ] customize test runner (jest)
127141
- [ ] add more example
142+
- [ ] postcss
128143
- [ ] scss support
129144
- [x] decorator support
130145
- [x] relay support

snippets/README.md

+5
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
# Code snippets
2+
3+
You need know what happen in monkey brain. So Snippets is better than helpers
4+
5+
- [snippets for [email protected]](cra-0.9.x.md)

snippets/cra-0.9.x.md

+32
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
# Code snippets for create-react-app 0.9.x
2+
3+
## webpack plugin
4+
5+
Add webpack plugin
6+
```js
7+
function addPlugin(config, plugin) {
8+
config.plugins.push(plugin);
9+
}
10+
```
11+
12+
## Find loader
13+
14+
```js
15+
function findLoader(config, callback) {
16+
var index = config.module.loaders.findIndex(callback);
17+
if (index === -1) throw Error('Loader not found');
18+
return config.module.loaders[index];
19+
}
20+
```
21+
22+
## Add Babel plugin
23+
requirement: `findLoader`
24+
```js
25+
function addBabelPlugins(webpackConfig, plugins) {
26+
var babelLoader = findLoader(webpackConfig, function (loader) {
27+
return loader.loader === 'babel'
28+
});
29+
babelLoader.query.plugins = (babelLoader.query.plugins || []).concat(plugins);
30+
}
31+
32+
```

0 commit comments

Comments
 (0)