-
Notifications
You must be signed in to change notification settings - Fork 7
/
webpack.config.js
80 lines (65 loc) · 1.83 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
const webpack = require('webpack');
const { env } = require('process');
const isProd = env.NODE_ENV === 'production';
const isProfile = env.PROFILE == 'true';
const isNonNil = x => x != null;
const BundleAnalyzerPlugin = require('webpack-bundle-analyzer').BundleAnalyzerPlugin;
const path = require('path');
const envVars = require('./src/client-env-vars.json');
// dependencies that we need to babelify ourselves
const unbabelifiedDependencies = [
'p-cancelable'
];
let conf = {
entry: {
bundle: './src/client/index.js',
polyfills: './src/client/polyfills.js'
},
output: {
filename: './build/[name].js'
},
devtool: 'inline-source-map',
module: {
rules: [
{
loader: 'babel-loader',
test: /\.js$/,
include: [
path.resolve(__dirname, 'src'),
].concat( unbabelifiedDependencies.map( pkg => path.resolve(__dirname, 'node_modules', pkg) ) ),
options: {
cacheDirectory: true
}
}
]
},
plugins: [
isProfile ? new BundleAnalyzerPlugin() : null,
new webpack.DefinePlugin({
'process.env': (() => {
const obj = {};
envVars.forEach(key => {
obj[key] = JSON.stringify(process.env[key]);
});
return obj;
})()
}),
new webpack.optimize.CommonsChunkPlugin({
name: 'deps',
filename: './build/deps.js',
minChunks( module ){
let context = module.context || '';
return context.indexOf('node_modules') >= 0 && !module.chunks.some(chunk => chunk.name === 'polyfills');
}
}),
new webpack.optimize.CommonsChunkPlugin({
name: 'webpackjsonp',
chunks: ['deps'],
minChunks: function(){
return false;
}
}),
isProd ? new webpack.optimize.UglifyJsPlugin() : null
].filter( isNonNil )
};
module.exports = conf;