-
Notifications
You must be signed in to change notification settings - Fork 15
/
Copy pathvite.config.mts
66 lines (62 loc) · 1.54 KB
/
vite.config.mts
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
import { resolve } from 'node:path'
import { defineConfig } from 'vite'
import htmlMinifier from 'vite-plugin-html-minifier'
import { minify } from 'html-minifier'
const htmlComponentFile = /\.html\?inline$/ // can have a prefix to html file names such as /\.component\.html\?inline$/
const minifyHTMLConfig = {
collapseInlineTagWhitespace: true,
collapseWhitespace: true,
minifyCSS: true,
minifyJS: true,
removeAttributeQuotes: true,
removeComments: true,
removeEmptyAttributes: true,
removeOptionalTags: true,
removeRedundantAttributes: true,
removeScriptTypeAttributes: true,
removeStyleLinkTypeAttributes: true,
sortAttributes: true,
sortClassName: true,
}
function htmlMinify() {
return {
name: 'html-minify',
transform(src: string, id: string): any {
if (htmlComponentFile.test(id)) {
return {
code: `export default \`${minify(src, minifyHTMLConfig)}\``,
map: null,
}
}
},
}
}
export default defineConfig({
base: './',
root: 'src',
build: {
outDir: resolve(__dirname, 'release'),
emptyOutDir: true,
rollupOptions: {
output: {
entryFileNames: 'assets/[name].js',
assetFileNames: 'assets/[name].[ext]',
},
},
assetsInlineLimit: 8192,
},
worker: {
rollupOptions: {
output: {
entryFileNames: 'assets/[name].js',
assetFileNames: 'assets/[name].[ext]',
},
},
},
plugins: [
htmlMinifier({
minify: true,
}),
htmlMinify(), // Used for importing 'about.html?inline'
],
})