-
Notifications
You must be signed in to change notification settings - Fork 188
/
webpack.config.js
172 lines (165 loc) · 4.13 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
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
const path = require('path')
const webpack = require('webpack')
const { BundleAnalyzerPlugin } = require('webpack-bundle-analyzer')
const TerserPlugin = require('terser-webpack-plugin')
const MiniCssExtractPlugin = require('mini-css-extract-plugin')
const CssMinimizerPlugin = require('css-minimizer-webpack-plugin')
const MomentLocalesPlugin = require('moment-locales-webpack-plugin')
const ReactRefreshWebpackPlugin = require('@pmmmwh/react-refresh-webpack-plugin')
const CssUrlRelativePlugin = require('css-url-relative-plugin')
const devMode = process.env.NODE_ENV !== 'production'
const pluginSystem = [
new MomentLocalesPlugin(),
new CssUrlRelativePlugin(),
new MiniCssExtractPlugin({
filename: 'wv.css'
})
]
/* Conditional Plugin Management */
if (devMode) {
pluginSystem.push(
new ReactRefreshWebpackPlugin()
)
}
if (process.env.ANALYZE_MODE === 'true') {
pluginSystem.push(new BundleAnalyzerPlugin())
}
if (process.env.DEBUG !== undefined) {
pluginSystem.push(
new webpack.DefinePlugin({ DEBUG: JSON.stringify(process.env.DEBUG) })
)
} else {
pluginSystem.push(
new webpack.DefinePlugin({ DEBUG: false })
)
}
const babelLoaderExcludes = [
/\.test\.js$/,
/fixtures\.js$/,
/core-js/
]
// Include any modules that need to be transpiled by babel-loader
const transpileDependencies = [
'react-visibility-sensor'
]
if (devMode) {
// Don't transpile any dependencies in /node_modules except those found
// in transpileDependencies array
babelLoaderExcludes.push(
new RegExp(`node_modules(?!(/|\\\\)(${transpileDependencies.join('|')})).*`)
)
}
module.exports = {
mode: devMode ? 'development' : 'production',
entry: './web/js/main.js',
output: {
filename: 'wv.js',
path: path.resolve(__dirname, 'web/build/'),
publicPath: './',
pathinfo: false,
clean: true
},
devtool: devMode && 'source-map',
devServer: {
devMiddleware: {
writeToDisk: true
},
static: path.join(__dirname, 'web'),
compress: true,
port: 3000,
hot: true,
historyApiFallback: true
},
optimization: {
minimizer: [
new TerserPlugin({
terserOptions: {
ecma: 5,
toplevel: true
}
}),
new CssMinimizerPlugin()
]
},
plugins: pluginSystem,
module: {
rules: [
{
test: /\.js$/,
use: {
loader: 'babel-loader',
options: {
compact: false, // fixes https://stackoverflow.com/questions/29576341/what-does-the-code-generator-has-deoptimised-the-styling-of-some-file-as-it-e
cacheDirectory: devMode,
plugins: [devMode && require.resolve('react-refresh/babel')].filter(Boolean)
}
},
exclude: babelLoaderExcludes
},
{
test: /\.(sa|sc|c)ss$/,
use: [
{
loader: MiniCssExtractPlugin.loader
},
{
loader: 'css-loader',
options: {
sourceMap: true,
importLoaders: 1
}
},
{
loader: 'postcss-loader',
options: {
postcssOptions: {
plugins: [
'cssnano',
'autoprefixer'
]
}
}
},
{
loader: 'sass-loader',
options: {
sourceMap: true
}
}
]
},
{
test: /\.(png|svg|jpg|jpeg|gif)$/i,
type: 'asset/resource',
generator: {
filename: 'images/[name][ext][query]'
}
},
{
test: /\.(woff|woff2|eot|ttf|otf)$/i,
type: 'asset/resource',
generator: {
filename: 'fonts/[name][ext][query]'
}
}
]
},
resolve: {
alias: {
googleTagManager$: path.resolve(
__dirname,
'./web/js/components/util/google-tag-manager.js'
)
},
fallback: {
fs: false
},
modules: ['node_modules', path.resolve(__dirname, 'web/scss')]
},
stats: {
// reduce output text on build - remove for more verbose
chunks: false,
modules: false,
children: false
}
}