-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathwebpack.config.js
More file actions
184 lines (181 loc) · 4.99 KB
/
Copy pathwebpack.config.js
File metadata and controls
184 lines (181 loc) · 4.99 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
const webpack = require('webpack');
const { CleanWebpackPlugin } = require('clean-webpack-plugin');
const CompressionPlugin = require('compression-webpack-plugin');
const FaviconsWebpackPlugin = require('favicons-webpack-plugin');
const ReplaceHashWebpackPlugin = require('replace-hash-webpack-plugin');
const zopfli = require('@gfx/zopfli');
const { name, version } = require('./package.json');
module.exports = [
{
entry: {
app: './src/js/index.js',
},
output: {
filename: '[name].[hash:6].js',
publicPath: '',
},
mode: process.env.NODE_ENV === 'production' ? 'production' : 'development',
module: {
rules: [
{
test: /\.js$/,
use: {
loader: 'babel-loader',
options: {
presets: [
[
'@babel/preset-env',
{
targets: {
browsers: [
'last 2 Chrome versions',
'last 2 Firefox versions',
'last 1 Safari version',
'last 1 Opera version',
],
},
},
],
],
plugins: ['syntax-dynamic-import'],
},
},
exclude: [
/node_modules/,
],
},
{
test: /\.css$/,
use: [
'style-loader',
'css-loader',
{
loader: 'postcss-loader',
options: {
ident: 'postcss',
plugins: [
require('autoprefixer')(), // eslint-disable-line
],
},
},
],
},
{
test: /\.(png|jpg|gif)$/,
use: [
{
loader: 'url-loader',
// Some bug (or some unwanted side effect) is currently
// preventing to use the 'limit' option below
// (because somehow '*.html' files ends up not being emited
// if that option is used...)
//
// options: {
// limit: 98304,
// },
},
],
},
{
// find these extensions in our css, copy the files to the outputPath,
// and rewrite the url() in our css to point them to the new (copied) location
test: /\.(woff(2)?|eot|otf|ttf|svg)(\?v=[0-9]\.[0-9]\.[0-9])?$/,
use: {
loader: 'file-loader',
options: {
outputPath: 'fonts/',
},
},
},
],
},
// optimization: {
// splitChunks: {
// cacheGroups: {
// commons: {
// test: /[\\/]node_modules[\\/]/,
// name: 'vendor',
// chunks: 'all',
// },
// },
// },
// },
optimization: {
// runtimeChunk: 'single',
splitChunks: {
chunks: 'all',
maxInitialRequests: Infinity,
minSize: 0,
cacheGroups: {
ol: {
test: /[\\/]node_modules[\\/](ol)[\\/]/,
name: 'ol',
},
itownsthree: {
test: /[\\/]node_modules[\\/](three|itowns)[\\/]/,
name: 'itownsthree',
},
vendor: {
test: /[\\/]node_modules[\\/](!ol)(!three)(!itowns)[\\/]/,
name: 'vendor',
},
},
},
},
plugins: [
new CleanWebpackPlugin({
cleanAfterEveryBuildPatterns: ['dist/*.*'],
watch: true,
}),
new webpack.ProvidePlugin({
Promise: 'bluebird',
}),
new ReplaceHashWebpackPlugin({
cwd: 'src',
src: '**/*.html',
dest: 'dist',
}),
new webpack.DefinePlugin({
CHOUCAS_VERSION: JSON.stringify(version),
APPLICATION_NAME: JSON.stringify(name),
}),
new FaviconsWebpackPlugin({
logo: './src/img/logo-choucas-small.png',
mode: 'webapp',
devMode: 'webapp',
favicons: {
appName: name,
icons: {
android: false,
appleIcon: false,
appleStartup: false,
coast: false,
favicons: true,
firefox: false,
yandex: false,
windows: false,
},
},
}),
],
watchOptions: {
poll: true,
},
},
];
if (process.env.NODE_ENV === 'production') {
// Theorically aiohttp should use the .gz version of the files when
// they exist (https://docs.aiohttp.org/en/stable/web_reference.html#aiohttp.web.UrlDispatcher.add_static)
module.exports[0].plugins.push(
new CompressionPlugin({
compressionOptions: { numiterations: 15 },
algorithm(input, compressionOptions, callback) {
return zopfli.gzip(input, compressionOptions, callback);
},
test: /\.(js|css|html|svg)$/,
threshold: 10240,
minRatio: 0.8,
deleteOriginalAssets: false,
}),
);
}