|
| 1 | +const webpack = require('webpack'); |
| 2 | +const conf = require('./gulp.conf'); |
| 3 | +const path = require('path'); |
| 4 | + |
| 5 | +const HtmlWebpackPlugin = require('html-webpack-plugin'); |
| 6 | +// Doing a webpack hack for es6: https://github.com/webpack-contrib/uglifyjs-webpack-plugin/issues/33 |
| 7 | +const UglifyJsPlugin = require('uglifyjs-webpack-plugin'); |
| 8 | +const FailPlugin = require('webpack-fail-plugin'); |
| 9 | +const ExtractTextPlugin = require('extract-text-webpack-plugin'); |
| 10 | +const pkg = require('../package.json'); |
| 11 | +const autoprefixer = require('autoprefixer'); |
| 12 | + |
| 13 | +module.exports = { |
| 14 | + module: { |
| 15 | + loaders: [ |
| 16 | + { |
| 17 | + test: /\.json$/, |
| 18 | + loaders: [ |
| 19 | + 'json-loader' |
| 20 | + ] |
| 21 | + }, |
| 22 | + { |
| 23 | + test: /\.js$/, |
| 24 | + exclude: /node_modules/, |
| 25 | + loader: 'eslint-loader', |
| 26 | + enforce: 'pre' |
| 27 | + }, |
| 28 | + { |
| 29 | + test: /\.css$/, |
| 30 | + loaders: ExtractTextPlugin.extract({ |
| 31 | + fallback: 'style-loader', |
| 32 | + use: 'css-loader?minimize!postcss-loader' |
| 33 | + }) |
| 34 | + }, |
| 35 | + { |
| 36 | + test: /\.js$/, |
| 37 | + exclude: /node_modules/, |
| 38 | + loaders: [ |
| 39 | + 'babel-loader' |
| 40 | + ] |
| 41 | + } |
| 42 | + ] |
| 43 | + }, |
| 44 | + plugins: [ |
| 45 | + new webpack.optimize.OccurrenceOrderPlugin(), |
| 46 | + new webpack.NoEmitOnErrorsPlugin(), |
| 47 | + FailPlugin, |
| 48 | + new HtmlWebpackPlugin({ |
| 49 | + template: conf.path.src('index.html') |
| 50 | + }), |
| 51 | + new webpack.DefinePlugin({ |
| 52 | + 'process.env.NODE_ENV': '"production"' |
| 53 | + }), |
| 54 | + new UglifyJsPlugin({ |
| 55 | + output: {comments: false}, |
| 56 | + compress: {unused: true, dead_code: true, warnings: false} // eslint-disable-line camelcase |
| 57 | + }), |
| 58 | + new ExtractTextPlugin('index-[contenthash].css'), |
| 59 | + new webpack.optimize.CommonsChunkPlugin({name: 'vendor'}), |
| 60 | + new webpack.LoaderOptionsPlugin({ |
| 61 | + options: { |
| 62 | + postcss: () => [autoprefixer] |
| 63 | + } |
| 64 | + }) |
| 65 | + ], |
| 66 | + output: { |
| 67 | + path: path.join(process.cwd(), conf.paths.dist), |
| 68 | + filename: '[name]-[hash].js' |
| 69 | + }, |
| 70 | + entry: { |
| 71 | + app: `./${conf.path.src('index')}`, |
| 72 | + vendor: Object.keys(pkg.dependencies) |
| 73 | + } |
| 74 | +}; |
0 commit comments