-
Notifications
You must be signed in to change notification settings - Fork 0
/
webpack.common.js
93 lines (85 loc) · 1.82 KB
/
webpack.common.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
const path = require("path"),
MiniCssExtractPlugin = require("mini-css-extract-plugin"),
HtmlWebpackPlugin = require("html-webpack-plugin");
// Rule for *.ts processing
const tsRule = {
test: /\.ts$/v,
loader: "ts-loader",
},
// Rule for *.css processing
cssRule = {
test: /\.css$/v,
use: [MiniCssExtractPlugin.loader, "css-loader"],
},
// Rule for icon processing
iconRule = {
test: /tv-icon-.*\.png$/v,
type: "asset/resource",
},
// Rule for image processing
imageRule = {
test: /(?:\.svg|apple-splash-.*\.png)$/v,
type: "asset/resource",
generator: {
filename: "images/[name][ext]",
},
},
// Rule for *.html processing
htmlRule = {
test: /\.html$/v,
include: /views/v,
loader: "html-loader",
},
// Rule for *.webmanifest processing
webmanifestRule = {
test: /\.webmanifest$/v,
loader: "webpack-webmanifest-loader",
type: "asset/resource",
},
// Creates index.html with the bundled resources
createIndexHtml = new HtmlWebpackPlugin(),
// Default config
config = {
mode: "development",
// Ensure that the context is the directory where the webpack.*.js config file is
context: path.resolve(__dirname),
// Default rules for all environments
module: {
rules: [tsRule],
},
// Default resolve paths
resolve: {
alias: {
"~": path.resolve(__dirname, "src"),
},
extensions: [".ts", "..."],
},
optimization: {
splitChunks: {
chunks: "all",
minSize: 0,
cacheGroups: {
defaultVendors: {
name: "vendor",
test: /\/node_modules\//v,
},
},
},
runtimeChunk: "single",
},
// Abort on first error
bail: true,
};
function extractCss(options = undefined) {
return new MiniCssExtractPlugin(options);
}
module.exports = {
cssRule,
iconRule,
imageRule,
htmlRule,
webmanifestRule,
extractCss,
createIndexHtml,
config,
};