-
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathvite.config.ts
More file actions
66 lines (65 loc) · 2.21 KB
/
vite.config.ts
File metadata and controls
66 lines (65 loc) · 2.21 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
import { defineConfig } from 'vite'
import tailwindcss from '@tailwindcss/vite'
import { ViteImageOptimizer } from 'vite-plugin-image-optimizer'
import zipPack from 'vite-plugin-zip-pack'
import fs from 'node:fs'
import path from 'node:path'
export default defineConfig(({ mode }) => {
const isProduction = mode === 'production'
const packageName = JSON.parse(fs.readFileSync(path.join('.', 'package.json'), 'utf-8')).name
const packageVersion = JSON.parse(fs.readFileSync(path.join('.', 'package.json'), 'utf-8')).version
return {
plugins: [
tailwindcss(),
ViteImageOptimizer({
test: /\.(jpe?g|png|gif|tiff|webp|svg|avif)$/i,
includePublic: true,
logStats: true,
jpeg: { quality: 80 },
jpg: { quality: 80 },
png: { quality: 80 },
webp: { quality: 80 },
}),
isProduction && zipPack({
inDir: './',
outDir: './',
outFileName: `${packageName}-${packageVersion}.zip`,
filter: (fileName, filePath) => {
if (filePath.includes('assets/dist') || fileName === 'assets') return true
if (fileName.endsWith('.hbs')) return true
if (filePath.includes('partials')) return true
if (fileName === 'package.json') return true
if (fileName === 'LICENSE') return true
return false
}
})
],
build: {
outDir: 'assets/dist',
emptyOutDir: true,
rollupOptions: {
input: {
main: 'assets/js/main.js',
post: 'assets/js/post.js',
},
output: {
entryFileNames: 'js/[name].js',
chunkFileNames: 'js/[name].js',
assetFileNames: (assetInfo) => {
if (assetInfo.name?.endsWith('.css')) {
return 'css/[name][extname]'
}
if (assetInfo.name && /\.(woff|woff2|eot|ttf|otf)$/i.test(assetInfo.name)) {
return `fonts/[name]-[hash][extname]`;
}
if (assetInfo.name && /\.(jpe?g|png|gif|svg|webp|avif)$/i.test(assetInfo.name)) {
const name = assetInfo.name.split('/').pop()
return `images/${name}`
}
return 'assets/[name][extname]'
}
}
}
}
}
})