|
| 1 | +var webpack = require('webpack'); |
| 2 | +var CleanPlugin = require('clean-webpack-plugin'); |
| 3 | + |
| 4 | +var isProductionMode = process.argv.indexOf('-production') != -1; |
| 5 | + |
| 6 | +var buildDistPath = 'builds'; |
| 7 | + |
| 8 | +module.exports = { |
| 9 | + devtool: isProductionMode ? undefined : 'source-map', |
| 10 | + entry: './src', |
| 11 | + output: { |
| 12 | + path: buildDistPath, |
| 13 | + filename: 'bundle.js', |
| 14 | + chunkFilename: '[name].js', //allow to name split chunks |
| 15 | + publicPath: buildDistPath + '/' |
| 16 | + }, |
| 17 | + module: { |
| 18 | + preLoaders: [ |
| 19 | + { |
| 20 | + test: /\.js/, |
| 21 | + loader: 'eslint', |
| 22 | + } |
| 23 | + ], |
| 24 | + loaders: [ |
| 25 | + { |
| 26 | + test: /\.js/, |
| 27 | + exclude: /(node_modules|bower_components)/, //avoid that babel will treaverse files third-party code //TODO is it needed? webpack entry is ./src' |
| 28 | + loader: 'babel', |
| 29 | + query: {presets: ['es2015']} |
| 30 | + }, |
| 31 | + { |
| 32 | + test: /\.html/, |
| 33 | + loader: 'html', |
| 34 | + }, |
| 35 | + { |
| 36 | + test: /\.scss$/, |
| 37 | + loaders: ["style", "css", "sass"] |
| 38 | + }, |
| 39 | + { |
| 40 | + test: /\.(png|gif|jpe?g|svg)$/i, |
| 41 | + loader: 'url', |
| 42 | + query: {limit: 10000} //if the asset is smaller than 10kb inline it, instead of giving the url |
| 43 | + } |
| 44 | + ] |
| 45 | + }, |
| 46 | + plugins: |
| 47 | + isProductionMode |
| 48 | + ? |
| 49 | + [ |
| 50 | + // Cleanup the builds/ folder before compiling |
| 51 | + new CleanPlugin(buildDistPath), |
| 52 | + // prevents creating chunks that would be too small to be worth loading separately |
| 53 | + new webpack.optimize.MinChunkSizePlugin({ |
| 54 | + minChunkSize: 51200, // ~50kb |
| 55 | + }), |
| 56 | + //extract common chunks dependency into a shared js |
| 57 | + new webpack.optimize.CommonsChunkPlugin({ |
| 58 | + name: 'main', // Move dependencies to our main file |
| 59 | + children: true, // Look for common dependencies in all children, |
| 60 | + minChunks: 2, // How many times a dependency must come up before being extracted |
| 61 | + }), |
| 62 | + //minify code |
| 63 | + new webpack.optimize.UglifyJsPlugin({ |
| 64 | + mangle: true, |
| 65 | + compress: { |
| 66 | + warnings: false, // Suppress uglification warnings |
| 67 | + }, |
| 68 | + }) |
| 69 | + ] |
| 70 | + : |
| 71 | + [] |
| 72 | +}; |
0 commit comments