-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathwebpack.config.js
More file actions
191 lines (174 loc) · 4.72 KB
/
webpack.config.js
File metadata and controls
191 lines (174 loc) · 4.72 KB
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
190
191
const path = require('path')
const webpack = require('webpack')
const merge = require('webpack-merge')
const HtmlWebpackPlugin = require('html-webpack-plugin')
const MiniCssExtractPlugin = require('mini-css-extract-plugin')
const CopyWebpackPlugin = require('copy-webpack-plugin')
const TerserPlugin = require('terser-webpack-plugin')
const OptimizeCSSAssetsPlugin = require('css-minimizer-webpack-plugin')
console.log('WEBPACK GO!')
// detemine build env
const TARGET_ENV = process.env.npm_lifecycle_event === 'build' ? 'production' : 'development'
// common webpack config
const commonConfig = {
entry: [
path.join(__dirname, 'front', 'static', 'index.js')
],
output: {
path: path.resolve(__dirname, 'dist/'),
filename: '[contenthash].js'
},
resolve: {
modules: ['node_modules'],
extensions: ['.js', '.elm']
},
module: {
noParse: /\.elm$/,
rules: [
{
test: /\.(eot|svg|ttf|woff(2)?)(\?v=\d+\.\d+\.\d+)?/,
type: 'asset/inline'
}
]
},
plugins: [
new HtmlWebpackPlugin({
template: path.join(__dirname, 'front', 'static', 'index.html'),
inject: 'body',
filename: 'index.html',
base: (TARGET_ENV === 'production') ? 'https://www.xaviermaso.com' : 'http://localhost:8080'
}),
new webpack.EnvironmentPlugin({
NODE_ENV: 'development'
})
]
}
// additional webpack settings for prod env (when invoked via 'npm run dev')
if (TARGET_ENV === 'development') {
console.log('Serving locally...')
module.exports = merge(commonConfig, {
devServer: {
static: [
{
directory: path.join(__dirname, 'front', 'static'),
watch: true
},
{
directory: path.join(__dirname, 'front', 'static', 'documents'),
watch: true
}
],
// Serve `index.html` for any 404;
// This approximates the server's behaviour when reaching pages served by front-end routing.
historyApiFallback: true,
hot: true,
host: '127.0.0.1',
port: 8080
},
mode: 'development',
module: {
rules: [
{
test: /\.elm$/,
exclude: [/elm-stuff/, /node_modules/],
use: [
{
loader: 'elm-reloader'
},
{
loader: 'elm-webpack-loader',
options: {
debug: true
}
}
]
},
{
test: /\.(css|scss)$/,
use: [
'style-loader',
{ loader: 'css-loader', options: { sourceMap: true } },
{ loader: 'postcss-loader', options: { sourceMap: true } },
{ loader: 'sass-loader', options: { sourceMap: true } }
]
}
]
}
})
}
// additional webpack settings for prod env (when invoked via 'npm run build')
if (TARGET_ENV === 'production') {
console.log('Building for prod...')
module.exports = merge(commonConfig, {
mode: 'production',
module: {
rules: [
{
test: /\.elm$/,
exclude: [/elm-stuff/, /node_modules/],
use: {
loader: 'elm-webpack-loader',
options: {
optimize: true
}
}
},
{
test: /\.(css|scss)$/,
use: [
MiniCssExtractPlugin.loader,
'css-loader',
'postcss-loader',
'sass-loader'
]
}
]
},
optimization: {
minimizer: [
new TerserPlugin({
terserOptions: {
compress: {
pure_funcs: ['F2', 'F3', 'F4', 'F5', 'F6', 'F7', 'F8', 'F9', 'A2', 'A3', 'A4', 'A5', 'A6', 'A7', 'A8', 'A9'],
pure_getters: true,
keep_fargs: false,
unsafe_comps: true,
unsafe: true
}
}
}),
new OptimizeCSSAssetsPlugin({})
]
},
plugins: [
new CopyWebpackPlugin({
patterns: Array.prototype.concat([
{
from: path.join(__dirname, 'front', 'static', 'img'),
to: path.join('static', 'img')
},
{
from: path.join(__dirname, 'front', 'static', 'img', 'favicon.ico')
}
], [
'atbdx2024_slides.pdf',
'bordeauxjs2026_slides.pdf',
'internship_report_2018.pdf',
'ptc2025_slides.pdf',
'xaviermaso.pdf'
].map((f) => {
return {
from: path.join(__dirname, 'front', 'static', 'documents', f),
to: f
}
})
)
}),
// extract CSS into a separate file
new MiniCssExtractPlugin({
filename: '[contenthash].css',
chunkFilename: '[id].[contenthash].css'
})
]
})
}