-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathvite.config.ts
More file actions
47 lines (44 loc) · 1.18 KB
/
vite.config.ts
File metadata and controls
47 lines (44 loc) · 1.18 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
import type { MinifierOptions } from "html-minifier-next";
import type { UserConfig } from "vite";
import { minify } from "html-minifier-next";
import { createFilter } from "vite";
const filter = createFilter("**/*.html");
const options: MinifierOptions = {
collapseWhitespace: true,
html5: true,
minifyCSS: true,
minifyJS: true,
removeAttributeQuotes: true,
removeComments: true,
removeRedundantAttributes: true,
removeScriptTypeAttributes: true,
removeStyleLinkTypeAttributes: true,
useShortDoctype: true
};
export default <UserConfig>{
plugins: [
{
// Yoinked from `@sergeymakinen/vite-plugin-html-minimize` with some
// changes.
name: "html-minifier",
apply: "build",
enforce: "post",
generateBundle: {
order: "post",
async handler(_, bundle) {
for (const assetOrChunk of Object.values(bundle)) {
if (
assetOrChunk.type === "asset" &&
filter(assetOrChunk.fileName)
) {
assetOrChunk.source = await minify(
assetOrChunk.source.toString(),
options
);
}
}
}
}
}
]
};