This repository has been archived by the owner on Feb 15, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 23
/
webpack.config.js
94 lines (89 loc) · 2.4 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
/* eslint-disable import/no-extraneous-dependencies */
const dotenv = require('dotenv');
const HtmlWebpackInlineSourcePlugin = require('html-webpack-inline-source-plugin');
const HTMLWebpackPlugin = require('html-webpack-plugin');
const UglifyJSPlugin = require('uglifyjs-webpack-plugin');
const path = require('path');
const webpack = require('webpack');
dotenv.config();
// Array of known environment variables whose value may be injected into the frontend as a key in
// process.env, allowing Node-like environment variable access in client-side logic.
const BUILD_ENV_VARS = [
'NODE_ENV',
'MAPBOX_API_TOKEN',
'ORION_SERVER_URL',
'PIWIK_URL',
'PIWIK_SITE_ID',
'PIWIK_CLIENT_TRACKER_NAME',
'PIWIK_SERVER_TRACKER_NAME',
];
const isProduction = process.env.NODE_ENV === 'production';
module.exports = {
mode: isProduction ? 'production' : 'development',
entry: {
main: './src',
},
output: {
path: path.resolve(__dirname, './dist'),
publicPath: '/dist/',
filename: '[name].js',
},
module: {
rules: [
{
test: /src\/.+\.js$/,
exclude: /node_modules/,
loader: 'babel-loader',
},
{
test: /\.html$/,
loader: 'html-loader',
},
{
test: /\.css$/,
use: ['style-loader', 'css-loader'],
},
],
// Mapbox modifies the globals in a way that Uglify statically parses incorrectly.
// As a workaround, skip parsing of the module completely.
// Reference: https://github.com/mapbox/mapbox-gl-js/issues/4359#issuecomment-303880888
noParse: /(mapbox-gl)\.js$/,
},
optimization: {
minimizer: [
new UglifyJSPlugin({
uglifyOptions: {
output: {
comments: false,
},
},
}),
],
},
performance: {
hints: false,
},
plugins: [
new webpack.ProgressPlugin(),
new webpack.DefinePlugin({
'process.env': BUILD_ENV_VARS
.filter((key) => key in process.env)
.reduce((acc, key) => ({
...acc,
[key]: JSON.stringify(process.env[key]),
}), {}),
}),
new HTMLWebpackPlugin({
template: 'src/resources/templates/index.html',
inlineSource: '.js$',
}),
new HtmlWebpackInlineSourcePlugin(),
isProduction && new webpack.LoaderOptionsPlugin({
minimize: true,
}),
].filter(Boolean),
devServer: {
historyApiFallback: true,
publicPath: '/',
},
};