-
Notifications
You must be signed in to change notification settings - Fork 21
/
webpack.config.babel.js
189 lines (174 loc) · 4.69 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
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
import path from 'path';
import dotenv from 'dotenv';
import HtmlWebpackPlugin from 'html-webpack-plugin';
import TerserPlugin from 'terser-webpack-plugin';
import webpack from 'webpack';
dotenv.config();
const PAGE_TITLE = 'Circles UBI | Wallet';
const CONFIG_KEYS = [
'API_SERVICE_EXTERNAL',
'BASE_PATH',
'ETHEREUM_NODE_ENDPOINT',
'GRAPH_NODE_EXTERNAL',
'HUB_ADDRESS',
'NODE_ENV',
'PATHFINDER_TYPE',
'PATHFINDER_SERVICE_ENDPOINT',
'PROXY_FACTORY_ADDRESS',
'RELAY_SERVICE_EXTERNAL',
'SAFE_ADDRESS',
'SAFE_DEFAULT_CALLBACK_HANDLER',
'SAFE_FUNDER_ADDRESS',
'SUBGRAPH_NAME',
];
const CONFIG_KEYS_OPTIONAL = [
'USER_NOTIFICATION',
'USER_NOTIFICATION_ICON_COLOR',
'USER_NOTIFICATION_BACKGROUND_COLOR',
'USER_NOTIFICATION_ICON',
'USER_NOTIFICATION_DASHBOARD',
'USER_NOTIFICATION_DASHBOARD_ICON',
'USER_NOTIFICATION_DASHBOARD_ICON_COLOR',
'USER_NOTIFICATION_DASHBOARD_BACKGROUND_COLOR',
'USER_NOTIFICATION_ERROR',
'USER_NOTIFICATION_ERROR_ICON',
'USER_NOTIFICATION_ERROR_ICON_COLOR',
'USER_NOTIFICATION_ERROR_BACKGROUND_COLOR',
'USER_NOTIFICATION_LOGIN',
'USER_NOTIFICATION_LOGIN_ICON',
'USER_NOTIFICATION_LOGIN_ICON_COLOR',
'USER_NOTIFICATION_LOGIN_BACKGROUND_COLOR',
'USER_NOTIFICATION_ONBOARDING',
'USER_NOTIFICATION_ONBOARDING_ICON',
'USER_NOTIFICATION_ONBOARDING_ICON_COLOR',
'USER_NOTIFICATION_ONBOARDING_BACKGROUND_COLOR',
'USER_NOTIFICATION_VALIDATION',
'USER_NOTIFICATION_VALIDATION_ICON',
'USER_NOTIFICATION_VALIDATION_ICON_COLOR',
'USER_NOTIFICATION_VALIDATION_BACKGROUND_COLOR',
'EXPLORER_URL',
'ISSUANCE_RATE_MONTH',
'SENTRY_DSN_URL',
'STORAGE_NAMESPACE',
];
const NODE_MODULES = 'node_modules';
const PATH_ASSETS = './assets';
const PATH_DIST = './build';
const PATH_LOCALES = './locales';
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;
}, {});
CONFIG_KEYS_OPTIONAL.forEach((key) => {
if (process.env[key]) {
envData[key] = JSON.stringify(process.env[key]);
}
});
const corePkg = require('./node_modules/@circles/core/package.json');
const pkg = require('./package.json');
envData.RELEASE_VERSION = `"${pkg.version}"`;
envData.CORE_RELEASE_VERSION = `"${corePkg.version}"`;
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_ASSETS),
locales: getPath(PATH_LOCALES),
'~': getPath(PATH_SRC),
},
},
module: {
rules: [
{
test: /\.js$/,
exclude,
use: ['babel-loader', 'eslint-loader'],
},
{
test: /\.css$/,
use: ['style-loader', 'css-loader'],
},
{
test: /\.svg$/,
use: ['@svgr/webpack'],
},
{
test: /\.(png|jp(e?)g|gif|woff(2?)|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: {
minimize: !isDevelopment,
minimizer: [
new TerserPlugin({
terserOptions: {
safari10: true,
},
}),
],
splitChunks: {
cacheGroups: {
commons: {
test: new RegExp(NODE_MODULES),
chunks: 'all',
name: 'lib',
},
},
},
},
plugins: [
new HtmlWebpackPlugin({
minify: isDevelopment
? false
: {
collapseWhitespace: true,
},
title: PAGE_TITLE,
favicon: getPath(`${PATH_ASSETS}/favicon.ico`),
template: getPath(`${PATH_SRC}/index.html`),
}),
new webpack.DefinePlugin({
'process.env': envData,
}),
],
};
};