-
Notifications
You must be signed in to change notification settings - Fork 1
/
webpack.config.js
92 lines (88 loc) · 2.19 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
91
92
'use strict';
const path = require('path');
const webpack = require('webpack');
const nodeEnv = process.env.NODE_ENV || 'development';
const isProduction = nodeEnv === 'production';
const fs = require('fs');
const ServiceWorkerWebpackPlugin = require('serviceworker-webpack-plugin');
const babelRc = JSON.parse(
fs.readFileSync(path.resolve('.babelrc')).toString()
);
module.exports = function(env) {
const rules = [
{
test: /\.js?$/,
include: [path.resolve('src')],
use: [
{
loader: require.resolve('babel-loader'),
options: {
presets: [
require.resolve('babel-preset-es2015'),
require.resolve('babel-preset-react'),
],
},
},
],
},
];
/*
CONFIG
*/
return {
performance: {
hints: isProduction ? 'warning' : false,
},
entry: {
main: path.resolve('src', 'client', 'index.js'),
common: ['preact', 'firebase'],
},
output: {
path: path.resolve('public'),
filename: isProduction ? '[name].[chunkhash].js' : '[name].js',
chunkFilename: isProduction ? '[chunkhash].js' : '[id].js',
publicPath: '/',
},
module: {
rules: rules,
},
devServer: {
port: 3000,
proxy: {
'/': 'http://localhost:3001',
},
hot: false,
inline: false,
},
plugins: [
new ServiceWorkerWebpackPlugin({
entry: path.resolve('src', 'serviceworker', 'index.js'),
}),
].concat(
isProduction
? [
new webpack.HashedModuleIdsPlugin(),
new webpack.optimize.CommonsChunkPlugin({
names: ['common', 'manifest'],
}),
new webpack.optimize.UglifyJsPlugin({
beautify: false,
comments: false,
compress: {
warnings: false,
drop_console: true,
},
mangle: {
except: ['webpackJsonp'],
screw_ie8: true,
},
}),
]
: [
new webpack.optimize.CommonsChunkPlugin({
names: ['common'],
}),
]
),
};
};