File tree Expand file tree Collapse file tree 3 files changed +55
-3
lines changed
Expand file tree Collapse file tree 3 files changed +55
-3
lines changed Original file line number Diff line number Diff 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```
4048npm install webpack-visualizer-plugin --save-dev
@@ -76,7 +84,7 @@ If you love decorators, you can add decorator support:
7684```
7785npm 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
8189function findLoader (config , callback ) {
8290 var index = config .module .loaders .findIndex (callback);
@@ -122,9 +130,16 @@ module.exports = function (webpackConfig, isDevelopment) {
122130```
123131related 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
Original file line number Diff line number Diff line change 1+ # Code snippets
2+
3+ You need know what happen in monkey brain. So Snippets is better than helpers
4+
5+ - [ snippets for cra@0.9.x ] ( cra-0.9.x.md )
Original file line number Diff line number Diff line change 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+ ```
You can’t perform that action at this time.
0 commit comments