-
Notifications
You must be signed in to change notification settings - Fork 3
/
webpack.config.js
125 lines (122 loc) · 3.07 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
113
114
115
116
117
118
119
120
121
122
123
124
125
var path = require('path')
var webpack = require('webpack')
var CopyWebpackPlugin = require('copy-webpack-plugin')
const HtmlWebpackPlugin = require('html-webpack-plugin');
// DEPLOY_PATH is set by the s3-deploy-action its value will be:
// `branch/[branch-name]/` or `version/[tag-name]/`
// See the following documentation for more detail:
// https://github.com/concord-consortium/s3-deploy-action/blob/main/README.md#top-branch-example
const DEPLOY_PATH = process.env.DEPLOY_PATH;
module.exports = {
mode: process.env.PRODUCTION ? 'production' : 'development',
entry: [
'./js/index.js'
],
devServer: {
client: {
overlay: false,
},
},
output: {
path: path.join(__dirname, 'dist'),
filename: 'app.js'
},
module: {
rules: [
{
test: /\.js$/,
exclude: /node_modules/,
loader: 'babel-loader'
},
{
test: /\.css$/,
use: ['style-loader', 'css-loader']
},
{
test: /\.less$/,
use: ['style-loader', 'css-loader', 'less-loader']
},
{
// Support ?123 suffix, e.g. ../fonts/m4d-icons.svg?3179539#iefix (for svg)
test: /\.(png|jpg|gif|woff|woff2|eot|ttf)((\?|#).*)?$/,
type: 'asset',
},
{
test: /\.glsl$/,
loader: 'raw-loader'
},
{
test: /\.kml$/,
loader: 'raw-loader'
},
{
// Pass global THREE variable to OrbitControls
test: /three[\\/]examples[\\/]js/,
loader: 'imports-loader',
options: {
imports: [
'namespace three THREE'
]
}
},
{
test: /leaflet-plugins\//,
loader: 'imports-loader',
options: {
imports: [
'namespace leaflet L'
]
}
},
{
test: /\.svg$/,
oneOf: [
{
// Do not apply SVGR import in CSS/LESS files.
issuer: /\.(less|css)$/,
type: 'asset',
},
{
issuer: /\.js$/,
loader: '@svgr/webpack',
options: {
svgoConfig: {
plugins: {
// SVGR removes viewbox by default. Disable this behavior.
removeViewBox: false
}
}
}
}
]
}
]
},
plugins: [
new HtmlWebpackPlugin({
filename: 'index.html',
template: 'js/index.html',
favicon: 'public/favicon.ico'
}),
...(DEPLOY_PATH ? [new HtmlWebpackPlugin({
filename: 'index-top.html',
template: 'js/index.html',
favicon: 'public/favicon.ico',
publicPath: DEPLOY_PATH
})] : []),
new CopyWebpackPlugin({
patterns: [
{ from: 'public' }
],
})
]
}
if (process.env.PRODUCTION) {
// We could use NODE_ENV directly (instead of PRODUCTION), but for some reason,
// when NODE_ENV is defined in command line, React does not seem to recognize it.
module.exports.plugins.push(
new webpack.DefinePlugin({
'process.env.NODE_ENV': JSON.stringify('production')
})
)
}