-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathwebpack.config.js
More file actions
105 lines (102 loc) · 2.67 KB
/
webpack.config.js
File metadata and controls
105 lines (102 loc) · 2.67 KB
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
93
94
95
96
97
98
99
100
101
102
103
104
105
'use strict';
var path = require('path');
var webpack = require('webpack');
var nodeEnv = process.env.NODE_ENV || 'development';
var isProduction = nodeEnv === 'production';
var ServiceWorkerWebpackPlugin = require('serviceworker-webpack-plugin');
module.exports = function(env) {
/*
Set up Babel transpiling
*/
var 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'),
],
},
},
],
},
];
return {
performance: {
hints: isProduction ? 'warning' : false,
},
entry: {
/*
The client is our main entrypoint
*/
main: path.resolve('src', 'client', 'index.js'),
/*
We include common libraries in its own file to avoid
downloading again
*/
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,
},
/*
The dev server needs to proxy all other requests not hitting
the client javascript files to your express server
*/
devServer: {
port: 3000,
proxy: {
'/': 'http://localhost:3001',
},
hot: false,
inline: false,
},
/*
The service worker plugin creates a service worker automatically for you
*/
plugins: [
new ServiceWorkerWebpackPlugin({
entry: path.resolve('src', 'serviceworker', 'index.js'),
}),
].concat(
isProduction
? [
/*
In production we use the hashed filename strategy to bust caches of javascript
file and also the serviceworker (as its contents will change)
*/
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'],
}),
]
),
};
};