|
| 1 | +var path = require('path') |
| 2 | + , webpack = require('webpack') |
| 3 | + , ExtractTextPlugin = require('extract-text-webpack-plugin') |
| 4 | + , pkg = require('../package.json'); |
| 5 | + |
| 6 | +module.exports = function makeConfig(options){ |
| 7 | + var entry = options.entry |
| 8 | + , plugins = options.plugins || [] |
| 9 | + |
| 10 | + var loaders = [ |
| 11 | + { test: /\.css$/, loader: options.extractStyles |
| 12 | + ? ExtractTextPlugin.extract('style-loader', 'css-loader') |
| 13 | + : 'style-loader!css-loader' }, |
| 14 | + |
| 15 | + { test: /\.less$/, loader: options.extractStyles |
| 16 | + ? ExtractTextPlugin.extract('style-loader', 'css-loader!less-loader') |
| 17 | + : 'style-loader!css-loader!less-loader' }, |
| 18 | + |
| 19 | + { test: /\.gif$/, loader: 'url-loader?mimetype=image/png' }, |
| 20 | + { test: /\.woff(2)?(\?v=[0-9]\.[0-9]\.[0-9])?$/, loader: 'url-loader?limit=10000&minetype=application/font-woff' }, |
| 21 | + { test: /\.(ttf|eot|svg)(\?v=[0-9]\.[0-9]\.[0-9])?$/, loader: 'file-loader?name=[name].[ext]' } |
| 22 | + ]; |
| 23 | + |
| 24 | + if (!options.noCompile) |
| 25 | + loaders.push( |
| 26 | + { test: /\.jsx$|\.js$/, loader: 'babel-loader', exclude: /node_modules/ }) |
| 27 | + |
| 28 | + if (options.hot){ |
| 29 | + loaders.splice(loaders.length - 1, 0, |
| 30 | + { test: /\.jsx$|\.js$/, loader: 'react-hot-loader', exclude: /node_modules/ }) |
| 31 | + |
| 32 | + plugins.push( |
| 33 | + new webpack.HotModuleReplacementPlugin(), |
| 34 | + new webpack.NoErrorsPlugin()) |
| 35 | + |
| 36 | + entry = [ |
| 37 | + 'webpack-dev-server/client?http://localhost:8080', |
| 38 | + 'webpack/hot/only-dev-server', |
| 39 | + entry |
| 40 | + ] |
| 41 | + } |
| 42 | + |
| 43 | + if (options.loaders) |
| 44 | + loaders = loaders.concat(options.loaders) |
| 45 | + |
| 46 | + |
| 47 | + |
| 48 | + if (options.minimize) |
| 49 | + plugins.push( |
| 50 | + new webpack.optimize.UglifyJsPlugin({ |
| 51 | + compress: { warnings: false, dead_code: true } //eslint-disable-line |
| 52 | + }), |
| 53 | + new webpack.optimize.DedupePlugin(), |
| 54 | + new webpack.NoErrorsPlugin()) |
| 55 | + else |
| 56 | + plugins.push( |
| 57 | + new webpack.DefinePlugin({ |
| 58 | + '__VERSION__': JSON.stringify(pkg.version) |
| 59 | + })); |
| 60 | + |
| 61 | + if ( options.production || options.minimize ) |
| 62 | + plugins.push(new webpack.DefinePlugin({ |
| 63 | + '__VERSION__': JSON.stringify(pkg.version), |
| 64 | + 'process.env': { NODE_ENV: JSON.stringify('production') } |
| 65 | + })) |
| 66 | + |
| 67 | + if (options.extractStyles) |
| 68 | + plugins.push( |
| 69 | + new ExtractTextPlugin(options.styleName || 'styles.css', { |
| 70 | + allChunks: true |
| 71 | + })) |
| 72 | + |
| 73 | + if (options.banner) { |
| 74 | + plugins.push( |
| 75 | + new webpack.BannerPlugin( |
| 76 | + '(c) ' + (new Date()).getFullYear() + ' Jason Quense | ' |
| 77 | + + 'https://github.com/jquense/react-widgets/blob/master/License.txt' |
| 78 | + , { entryOnly : true })) |
| 79 | + } |
| 80 | + |
| 81 | + return { |
| 82 | + cache: true, |
| 83 | + |
| 84 | + devtool: options.devtool, |
| 85 | + |
| 86 | + entry: entry, |
| 87 | + |
| 88 | + output: options.output, |
| 89 | + |
| 90 | + externals: options.externals, |
| 91 | + |
| 92 | + resolve: { |
| 93 | + extensions: ['', '.js', '.jsx'], |
| 94 | + alias: { |
| 95 | + 'react-widgets': path.join(__dirname, '..', 'src') |
| 96 | + } |
| 97 | + }, |
| 98 | + |
| 99 | + module: { |
| 100 | + loaders: loaders |
| 101 | + }, |
| 102 | + |
| 103 | + plugins: plugins, |
| 104 | + |
| 105 | + node: { |
| 106 | + Buffer: false |
| 107 | + } |
| 108 | + } |
| 109 | +} |
0 commit comments