-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathwebpack.config.js
124 lines (114 loc) · 3.1 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
const { join } = require("path");
const CopyPlugin = require("copy-webpack-plugin");
const HtmlPlugin = require("html-webpack-plugin");
const IconduitHtmlPlugin = require("@iconduit/html-webpack-plugin");
const { GenerateSW } = require("workbox-webpack-plugin");
const consumer = require("./assets/iconduit.consumer.js");
const srcPath = join(__dirname, "src");
const manifestPath = join(__dirname, "assets/site.iconduitmanifest");
const buildPath = join(__dirname, "artifacts/webpack/build");
module.exports = (_, { mode = "development" } = {}) => {
const isProduction = mode === "production";
const {
manifest: { name },
} = consumer;
const networkFirstAssets = [
/\bapple-touch-startup[^/]*\.png$/,
/\bbrowserconfig[^/]*\.xml$/,
/\bopen-graph[^/]*\.png$/,
/\bsafari-mask-icon[^/]*\.svg$/,
/\btwitter-card[^/]*\.png$/,
/\bwindows-tile[^/]*\.png$/,
];
const networkOnlyAssets = [/\bVERSION$/];
const workboxExclude = [
/\.map$/,
...networkFirstAssets,
...networkOnlyAssets,
];
const workboxRuntimeCaching = [
...networkFirstAssets.map((urlPattern) => ({
urlPattern,
handler: "NetworkFirst",
})),
...networkOnlyAssets.map((urlPattern) => ({
urlPattern,
handler: "NetworkOnly",
})),
];
return {
mode,
plugins: [
new HtmlPlugin({
template: "src/index.html",
title: name,
}),
new IconduitHtmlPlugin({ manifestPath }),
new GenerateSW({
cacheId: "iconduit-website",
cleanupOutdatedCaches: true,
exclude: workboxExclude,
runtimeCaching: workboxRuntimeCaching,
}),
new CopyPlugin({
patterns: [
{
from: consumer.absoluteImagePath("faviconIco", "container"),
},
],
}),
],
devtool: "source-map",
output: {
path: join(buildPath, isProduction ? "production" : "development"),
filename: isProduction ? "[name].[contenthash].js" : "[name].js",
assetModuleFilename: isProduction
? "[name].[contenthash][ext]"
: "[name][ext]",
publicPath: "/",
},
entry: {
polyfill: "./src/polyfill.js",
main: "./src/index.js",
},
module: {
rules: [
{
test: /\.js$/,
include: [srcPath],
use: "babel-loader",
},
{
test: /\.(png|svg)$/,
type: "asset/resource",
},
{
test: /\.webmanifest$/i,
type: "asset/resource",
use: "@iconduit/webmanifest-loader",
},
{
test: /\/browserconfig\.xml$/i,
type: "asset/resource",
use: "@iconduit/browserconfig-loader",
},
],
},
performance: {
assetFilter(assetFilename) {
if (/\.map$/.test(assetFilename)) return false;
if (/^\./.test(assetFilename)) return false;
return true;
},
},
stats: {
children: isProduction,
entrypoints: isProduction,
excludeAssets: isProduction ? () => false : /\.map$/,
modules: isProduction,
},
devServer: {
hot: true,
},
};
};