-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathwebpack.production.config.js
88 lines (81 loc) · 2.36 KB
/
webpack.production.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
78
79
80
81
82
83
84
85
86
87
88
const webpack = require('webpack');
const {resolve, join} = require('path');
const HtmlWebpackPlugin = require('html-webpack-plugin');
const ExtractTextPlugin = require('extract-text-webpack-plugin');
const CompressionPlugin = require("compression-webpack-plugin");
const VENDOR_LIBS = [
'apiai', 'bulma', 'halogen', 'react', 'react-dom', 'redux', 'react-router',
'react-delay-render', 'react-progressive-image', 'react-redux', 'redux-thunk',
'styled-components', 'superagent', 'moment-timezone'
]
const ASSET_PATH = process.env.ASSET_PATH || '/';
module.exports = {
entry: {
main: resolve(__dirname, 'src/index.js'),
vendor: VENDOR_LIBS
},
output: {
filename: '[chunkhash].[name].js',
path: resolve(__dirname, 'build'),
publicPath: ASSET_PATH
},
devtool: 'source-map',
module: {
rules: [
{
test: /\.js$/,
use: ['babel-loader'],
exclude: /node_modules/
},
{
test: /\.css$/,
loader: ExtractTextPlugin.extract({
loader: 'style-loader!css-loader?sourceMap!postcss-loader'
}),
include: /node_modules/
},
{
test: /\.sass$/,
loader: 'style-loader!css-loader!sass-loader',
include: /node_modules/
},
{
test: /\.json$/,
use: ['json-loader']
}
]
},
resolve: {
alias: {
'react-redux': join(__dirname, '/node_modules/react-redux/dist/react-redux.min')
}
},
plugins: [
new HtmlWebpackPlugin({
template: resolve(__dirname, 'index.html')
}),
new ExtractTextPlugin({ filename: 'bundle.css', disable: false, allChunks: true }),
require('autoprefixer'),
// new webpack.optimize.UglifyJsPlugin(),
new webpack.optimize.CommonsChunkPlugin({
names: ['vendor', 'manifest'],
// Check if the vendor dependencies present in the array declared are in node_modules folder or not
minChunks: function (module) {
return module.context && module.context.indexOf('node_modules') !== -1;
}
}),
new webpack.DefinePlugin({
'process.env': {
NODE_ENV: JSON.stringify('production'),
ASSET_PATH: JSON.stringify(ASSET_PATH)
}
}),
new CompressionPlugin({
asset: "[path].gz[query]",
algorithm: "gzip",
test: /\.js$|\.html$/,
threshold: 10240,
minRatio: 0.8
})
]
}