-
Notifications
You must be signed in to change notification settings - Fork 21
/
webpack.config.js
90 lines (87 loc) · 2.52 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
78
79
80
81
82
83
84
85
86
87
88
89
90
require('dotenv').config();
const path = require('path');
const webpack = require('webpack'); // eslint-disable-line import/no-extraneous-dependencies
const WebpackAnalyser = require('webpack-bundle-size-analyzer').WebpackBundleSizeAnalyzerPlugin; // eslint-disable-line import/no-extraneous-dependencies
const HtmlWebpackPlugin = require('html-webpack-plugin'); // eslint-disable-line import/no-extraneous-dependencies
const ExtractTextPlugin = require('extract-text-webpack-plugin'); // eslint-disable-line import/no-extraneous-dependencies
const isProduction = process.env.NODE_ENV === 'production';
module.exports = {
entry: './src/App.jsx',
output: {
filename: 'bundle.[hash].js',
publicPath: '/',
path: path.resolve(__dirname, 'dist'),
},
resolve: {
extensions: ['.jsx', '.js'],
},
module: {
loaders: [{
test: /\.jsx?$/,
exclude: /node_modules/,
loader: 'babel-loader',
}, {
test: /\.css$/,
use: ExtractTextPlugin.extract({
use: [
{
loader: 'css-loader',
options: {
importLoaders: 1,
minimize: process.env.NODE_ENV === 'production',
},
},
'postcss-loader',
],
}),
}, {
test: /\.(png|svg)$/,
loader: 'url-loader',
}],
},
devtool: isProduction ? 'cheap-module-source-map' : 'cheap-eval-source-map',
plugins: [
new WebpackAnalyser('./dist/report.txt'),
new webpack.EnvironmentPlugin([
'MONZO_CLIENT_ID',
'MONZO_REDIRECT_URI',
'GOOGLE_MAPS_API_KEY',
].concat(isProduction ? ['NODE_ENV'] : [])),
new HtmlWebpackPlugin({
template: './src/index.html',
...(isProduction ? {
minify: {
collapseWhitespace: true,
collapseInlineTagWhitespace: true,
removeComments: true,
removeRedundantAttributes: true,
},
} : {}),
}),
new ExtractTextPlugin('bundle.[chunkhash].css'),
].concat(isProduction ? [
new webpack.optimize.ModuleConcatenationPlugin(),
new webpack.HashedModuleIdsPlugin(),
new webpack.optimize.UglifyJsPlugin({
mangle: true,
compress: {
warnings: false,
conditionals: true,
unused: true,
comparisons: true,
sequences: true,
dead_code: true,
evaluate: true,
if_return: true,
join_vars: true,
},
comments: false,
}),
] : []),
devServer: {
historyApiFallback: true,
proxy: {
'/api': 'http://127.0.0.1:8081',
},
},
};