| Conditions | 1 |
| Paths | 1 |
| Total Lines | 127 |
| Lines | 0 |
| Ratio | 0 % |
| Changes | 1 | ||
| Bugs | 0 | Features | 0 |
Small methods make your code easier to understand, in particular if combined with a good name. Besides, if your method is small, finding a good name is usually much easier.
For example, if you find yourself adding comments to a method's body, this is usually a good sign to extract the commented part to a new method, and use the comment as a starting point when coming up with a good name for this new method.
Commonly applied refactorings include:
If many parameters/temporary variables are present:
| 1 | const webpack = require('webpack'); |
||
| 8 | module.exports = (env) => { |
||
| 9 | const { ifProd, ifNotProd } = getIfUtils(env); |
||
| 10 | |||
| 11 | return { |
||
| 12 | context: resolve(__dirname, './app/Resources/assets'), |
||
| 13 | devtool: ifProd('source-map', 'cheap-module-source-map'), |
||
| 14 | entry: { |
||
| 15 | main: './main.js', |
||
| 16 | vendor: [ |
||
| 17 | 'admin-lte', |
||
| 18 | 'bootstrap', |
||
| 19 | 'fastclick', |
||
| 20 | 'holderjs', |
||
| 21 | 'jquery-slimscroll', |
||
| 22 | 'jquery', |
||
| 23 | ] |
||
| 24 | }, |
||
| 25 | output: { |
||
| 26 | path: resolve(__dirname, './web'), |
||
| 27 | filename: ifProd('js/[name].[hash].js', 'js/[name].js'), |
||
| 28 | pathinfo: ifNotProd(), // Include comments with information about the modules. |
||
| 29 | }, |
||
| 30 | resolve: { |
||
| 31 | extensions: ['.js'], |
||
| 32 | }, |
||
| 33 | module: { |
||
| 34 | rules: [ |
||
| 35 | { |
||
| 36 | test: require.resolve('jquery'), |
||
| 37 | use: [ |
||
| 38 | { |
||
| 39 | loader: 'expose-loader', |
||
| 40 | query: 'jQuery' |
||
| 41 | }, |
||
| 42 | { |
||
| 43 | loader: 'expose-loader', |
||
| 44 | query: '$' |
||
| 45 | } |
||
| 46 | ] |
||
| 47 | }, |
||
| 48 | { |
||
| 49 | // Do not transform vendor's CSS with CSS-modules |
||
| 50 | // The point is that they remain in global scope. |
||
| 51 | test: /\.css$/, |
||
| 52 | include: /node_modules/, |
||
| 53 | loader: ifNotProd( |
||
| 54 | [ |
||
| 55 | 'style-loader', |
||
| 56 | { |
||
| 57 | loader: 'css-loader', |
||
| 58 | query: { sourceMap: true, } |
||
| 59 | } |
||
| 60 | ], |
||
| 61 | ExtractTextPlugin.extract({ |
||
| 62 | fallbackLoader: 'style-loader', |
||
| 63 | loader: [ |
||
| 64 | { |
||
| 65 | loader: 'css-loader', |
||
| 66 | // @TODO replace with "options" when ExtractTextPlugin is fixed |
||
| 67 | query: { |
||
| 68 | minimize: true, |
||
| 69 | } |
||
| 70 | } |
||
| 71 | ], |
||
| 72 | |||
| 73 | }) |
||
| 74 | ) |
||
| 75 | }, |
||
| 76 | { |
||
| 77 | test: /\.(woff(2)?|eot|ttf|svg)(\?[a-z0-9=.]+)?$/, |
||
| 78 | use: 'file-loader?name=fonts/[name].[hash].[ext]' |
||
| 79 | }, |
||
| 80 | { |
||
| 81 | test: /\.(gif|png|jpe?g|svg)$/i, |
||
| 82 | use: removeEmpty( |
||
| 83 | [ |
||
| 84 | { |
||
| 85 | loader: 'url-loader', |
||
| 86 | query: { |
||
| 87 | limit: 10 * 1000, // byte limit in bytes ( 10kb ) |
||
| 88 | hashType: 'sha512', |
||
| 89 | digestType: 'hex', |
||
| 90 | name: 'images/[name].[hash].[ext]', |
||
| 91 | } |
||
| 92 | }, |
||
| 93 | ifProd( |
||
| 94 | { |
||
| 95 | loader: 'image-webpack-loader', |
||
| 96 | query: { |
||
| 97 | progressive: true, |
||
| 98 | optimizationLevel: 7, |
||
| 99 | interlaced: false, |
||
| 100 | pngquant: { |
||
| 101 | quality: '65-90', |
||
| 102 | speed: 4 |
||
| 103 | } |
||
| 104 | } |
||
| 105 | } |
||
| 106 | ) |
||
| 107 | ] |
||
| 108 | ) |
||
| 109 | }, |
||
| 110 | ] |
||
| 111 | }, |
||
| 112 | plugins: removeEmpty([ |
||
| 113 | ifProd(new ExtractTextPlugin({ |
||
| 114 | filename: 'css/[name].[contenthash].css', |
||
| 115 | allChunks: true, |
||
| 116 | })), |
||
| 117 | ifProd( |
||
| 118 | new AssetsPlugin({ path: join(__dirname, 'web', 'bundles') }) |
||
| 119 | ), |
||
| 120 | ifProd(new webpack.optimize.UglifyJsPlugin({ |
||
| 121 | compress: { |
||
| 122 | screw_ie8: true, |
||
| 123 | warnings: false, |
||
| 124 | }, |
||
| 125 | output: { comments: false } |
||
| 126 | })), |
||
| 127 | new webpack.optimize.CommonsChunkPlugin({ |
||
| 128 | name: 'vendor', |
||
| 129 | minChunks: Infinity, |
||
| 130 | }), |
||
| 131 | new ProgressBarPlugin(), |
||
| 132 | ]), |
||
| 133 | }; |
||
| 134 | } |
||
| 135 |