-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathwebpack.config.js
77 lines (72 loc) · 2.09 KB
/
webpack.config.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
/*eslint-env node*/
require('dotenv').config()
const webpack = require('webpack')
const Path = require('path')
const SWPrecachePlugin = require('sw-precache-webpack-plugin')
const CompressionPlugin = require('compression-webpack-plugin')
const UglifyJsPlugin = require('uglifyjs-webpack-plugin')
const ExtractTextWebpackPlugin = require('extract-text-webpack-plugin')
const HtmlWebpackPlugin = require('html-webpack-plugin')
const OptimizeCssAssetsPlugin = require('optimize-css-assets-webpack-plugin')
const swConfig = require('./sw.config')
const debug = process.env.NODE_ENV !== 'production'
module.exports = {
context: Path.join(__dirname, 'src'),
devtool: debug ? 'eval-source-map' : debug,
entry: {
app: './js/client.js',
vendor: [
'babel-polyfill',
'react',
'react-redux',
'redux',
'react-router-dom'
]
},
module: {
rules: [
{
test: /^(?!.*\.test\.js$).*\.js$/,
exclude: /node_modules/,
loader: 'babel-loader'
},
{
test: /\.scss$/,
use: ExtractTextWebpackPlugin.extract({
fallback: 'style-loader',
use: ['css-loader', 'sass-loader', 'postcss-loader']
})
}
]
},
output: {
path: Path.join(__dirname, 'dist'),
filename: '[name].bundle.js'
},
plugins: debug ? [] : [
new ExtractTextWebpackPlugin('styles.css'),
new UglifyJsPlugin(),
new webpack.DefinePlugin({
'process.env.NODE_ENV': JSON.stringify(process.env.NODE_ENV || 'development')
}),
new webpack.optimize.CommonsChunkPlugin({
name: ['vendor'],
minChunks: Infinity,
filename: '[name].bundle.js'
}),
new CompressionPlugin({
asset: '[path].gz[query]',
test: /\.js$/
}),
new OptimizeCssAssetsPlugin({
assetNameRegExp: /\.css$/g,
cssProcessor: require('cssnano'),
cssProcessorOptions: { discardComment: { removeAll: true }}
}),
new HtmlWebpackPlugin({
template: Path.join(__dirname, 'src', 'template.html'),
filename: Path.join(__dirname, 'index.html')
}),
new SWPrecachePlugin(swConfig)
]
}