-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathwebpack.config.js
112 lines (105 loc) · 2.56 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
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
const path = require('path');
const HtmlWebpackPlugin = require('html-webpack-plugin');
const FlowWebpackPlugin = require('flow-webpack-plugin');
const BundleAnalyzerPlugin = require('webpack-bundle-analyzer').BundleAnalyzerPlugin;
const webpack = require('webpack');
const baseConfig = (env) => ({
context: __dirname,
entry: './frontend/src/index.jsx',
mode: 'development',
devtool: 'eval-source-map',
output: {
path: path.resolve('./frontend/dist'),
filename: 'index_bundle.js'
},
plugins: [
new HtmlWebpackPlugin({
title: 'Callblocker',
template: './frontend/public/index.html'
}),
// Ugh, moment.js locales are enormous!
new webpack.IgnorePlugin(/^\.\/locale$/, /moment$/)
],
devServer: {
contentBase: './frontend/dist',
historyApiFallback: true,
host: '0.0.0.0',
proxy: {
'/api': 'http://0.0.0.0:8000'
}
},
resolve: {
extensions: ['.js', '.jsx']
},
module: {
rules: [
{
test: /\.(js|jsx)$/,
exclude: /node_modules/,
use: {
loader: "babel-loader"
}
},
{
test: /\.css$/,
exclude: /node_modules/,
use: [
'style-loader',
'css-loader'
]
}
]
}
});
const IDENTITY = (base) => base
const OPTIONS = {
// Uses different source maps in production.
prod: {
set: 'PRODUCTION',
unset: 'DEVELOPMENT',
apply_set: (base) => ({
...base,
mode: 'production',
devtool: 'source-map'
}),
apply_unset: IDENTITY
},
// Disables flow when building in the Raspberry Pi.
rpi: {
set: 'Raspberry Pi',
unset: 'Web',
apply_set: IDENTITY,
apply_unset: (base) => ({
...base,
plugins: base.plugins.concat(new FlowWebpackPlugin())
})
},
// Disables bundle size analysis unless requested.
sizes: {
set: 'with Bundle Size Analysis',
unset: 'without Bundle Size Analysis',
apply_set: (base) => ({
...base,
plugins: base.plugins.concat(new BundleAnalyzerPlugin())
}),
apply_unset: IDENTITY
}
};
function formatOpts(env) {
return (
Object.entries(OPTIONS)
.map(([option, settings]) => env[option] ? settings.set : settings.unset)
.join(', ')
)
}
const applyConfig = (env) => Object
.entries(OPTIONS)
.reduce((config, [option, setting]) => {
return env[option] ? setting.apply_set(config) : setting.apply_unset(config)
},
baseConfig(env)
);
module.exports = function (env = {}, argv) {
console.log(`Running a <<${formatOpts(env)}>> build.`);
return applyConfig(env);;
};