-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathwebpack.config.mjs
More file actions
136 lines (131 loc) · 5.06 KB
/
webpack.config.mjs
File metadata and controls
136 lines (131 loc) · 5.06 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
import * as path from 'path';
/*
* DISREGARD: just a vent in German
*
* Haben wir noch Namespaces dabei? Keins mehr? Keine mehr? Zwei noch? Hast du
* die Namespaces noch genommen? Hallo? Der ist ein bisschen ein Otto
* geworden... Aber ich hab' Respekt vor dem. Ich hät jetzt Bock auf Namespaces.
* Boah, wir würden so namespacen... `@webpackcontrib/css-minimizer-plugin`,
* `webpack-css-minimizer-plugin`...
*/
import MiniCssExtractPlugin from 'mini-css-extract-plugin';
import CssMinimizerPlugin from 'css-minimizer-webpack-plugin';
export default (env, arg) => {
return {
mode: "production",
performance: {
hints: 'warning',
maxEntrypointSize: 512000,
/**
* Font files are larger than what's recommended by webpack.
*
* First of: OWN YOUR ASSETS! Don't expect everything to be hosted
* via a CDN from the start. That's optimizations you can think
* about later on.
*
* Second: That's not the whole picture. HTTP supports gzip and even
* brotli compression, which both have a high compression ratio.
* We're mainly worried about transmission sizes, not storage sizes,
* so nagging about the original file size is not only overly
* excessive, it tries to enforce optimization where it's not
* necessary.
*/
maxAssetSize: 512000,
/**
* just dropping this comment to vent a little...
*
* ECMAScript dynamic imports? Check. Though unconvential, I see why
* it was designed that way. webpack code-splitting? Not very well
* documented and some very confusing behavior, where it's difficult
* to discern the MUSTs from the SHOULDs. All I wanted was for
* webpack to resolve the URL and place the referenced asset where I
* want it to in accordance with whatever I defined in the webpack
* configuration. Instead I'm getting some random warnings about
* file sizes and chunking recommendations. Enabling chunking, still
* the same warning... So deep down the rabbit hole, I almost forgot
* what I was even trying to do: just reference a freaking file and
* have it resolved, that's all! If the warning was just printed to
* console stdout, fine. No, instead it's this massive overlay in
* the HMR that makes the web page unusable... For a warning... With
* the text even being in red... I could just disable the warnings?
* I'm not in the business of ignoring warnings. You warn me, I act
* upon it.
*/
assetFilter: assetFilename => {
return !assetFilename.endsWith('.mp3');
},
},
resolve: {
extensions: ['.ts', '.tsx', '.js']
},
entry: {
theme: [
"./src/script/main.ts",
"./src/style/main.scss"
]
},
output: {
filename: "script/[name].js",
path: path.resolve('build','release'),
},
plugins: [
new MiniCssExtractPlugin({ filename: "style/[name].css" }),
],
optimization: { minimizer: [`...`, new CssMinimizerPlugin()] },
module: {
rules: [
{
test: /\.s?[ca]ss$/i,
use: [
MiniCssExtractPlugin.loader,
{ loader: "css-loader", options: { sourceMap: true } },
{ loader: "postcss-loader", options: { sourceMap: true } },
{
loader: 'sass-loader',
options: {
sassOptions: {
silenceDeprecations: ['global-builtin'],
},
},
},
],
},
{
test: /\.tsx?$/,
use: [
{
loader: 'ts-loader',
options: {
configFile: 'tsconfig.json'
}
}
],
exclude: /node_modules/,
},
{
test: /\.(woff|woff2|eot|ttf)$/,
type: 'asset/resource',
generator: {
filename: 'font/[hash][ext][query]'
}
},
{
test: /\.(mp3)$/,
include: /vendor/,
type: 'asset/resource',
generator: {
filename: 'audio/[name][ext]',
},
},
{
test: /\.(gif)$/,
include: /vendor/,
type: 'asset/resource',
generator: {
filename: 'image/[name][ext]',
},
},
],
},
};
}