-
Notifications
You must be signed in to change notification settings - Fork 0
/
webpack.config.babel.js
124 lines (114 loc) · 2.77 KB
/
webpack.config.babel.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
113
114
115
116
117
118
119
120
121
122
123
124
import path from 'path';
import HtmlWebpackPlugin from 'html-webpack-plugin';
import dotenv from 'dotenv';
import webpack from 'webpack';
dotenv.config();
const CONFIG_KEYS = [
'API_SERVICE_EXTERNAL',
'BASE_PATH',
'ETHEREUM_NODE_WS',
'GRAPH_NODE_EXTERNAL',
'HUB_ADDRESS',
'NODE_ENV',
'PROXY_FACTORY_ADDRESS',
'RELAY_FUNDER_ADDRESS',
'RELAY_SENDER_ADDRESS',
'RELAY_SERVICE_EXTERNAL',
'SAFE_ADDRESS',
'SUBGRAPH_NAME',
];
const NODE_MODULES = 'node_modules';
const PATH_DIST = './build';
const PATH_SRC = './src';
function getPath(filePath) {
return path.resolve(__dirname, filePath);
}
const envData = CONFIG_KEYS.reduce((acc, key) => {
// Check for missing config variables
if (!process.env[key]) {
throw new Error(`${key} not set for ${process.env.NODE_ENV}!`);
}
// Pass values over to app from given environment
acc[key] = JSON.stringify(process.env[key]);
return acc;
}, {});
export default () => {
const isDevelopment = process.env.NODE_ENV === 'development';
const filename = isDevelopment ? '[name]' : '[name]-[contenthash:4]';
const exclude = new RegExp(NODE_MODULES);
return {
mode: isDevelopment ? 'development' : 'production',
entry: {
app: getPath(`${PATH_SRC}/index.js`),
},
output: {
filename: `${filename}.js`,
sourceMapFilename: `${filename}.js.map`,
path: getPath(PATH_DIST),
publicPath: '/',
},
resolve: {
modules: [NODE_MODULES],
alias: {
'~': getPath(PATH_SRC),
},
},
module: {
rules: [
{
test: /\.js$/,
exclude,
use: ['babel-loader', 'eslint-loader'],
},
{
test: /\.css$/,
use: ['style-loader', 'css-loader'],
},
{
test: /\.(png|jp(e?)g|gif|woff(2?)|svg|ttf|eot)$/,
exclude,
use: [
{
loader: 'file-loader',
options: {
name: `[path]${filename}.[ext]`,
},
},
],
},
],
},
devtool: 'source-map',
devServer: {
clientLogLevel: 'silent',
contentBase: getPath(PATH_DIST),
historyApiFallback: true,
liveReload: false,
},
optimization: {
splitChunks: {
cacheGroups: {
commons: {
test: new RegExp(NODE_MODULES),
chunks: 'all',
name: 'lib',
},
},
},
},
plugins: [
new HtmlWebpackPlugin({
minify: isDevelopment
? false
: {
collapseWhitespace: true,
},
favicon: getPath(`${PATH_SRC}/favicon.ico`),
template: getPath(`${PATH_SRC}/index.html`),
}),
new webpack.DefinePlugin({
'process.env': envData,
}),
],
};
};