-
Notifications
You must be signed in to change notification settings - Fork 0
/
vite.config.ts
88 lines (86 loc) 路 1.96 KB
/
vite.config.ts
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
import { resolve } from 'path';
import { defineConfig } from 'vite';
import { createHtmlPlugin } from 'vite-plugin-html';
import viteImagemin from 'vite-plugin-imagemin';
import react from '@vitejs/plugin-react';
const root = resolve(__dirname, 'src');
const outDir = resolve(__dirname, 'dist');
const assetsDir = 'resources';
// https://vitejs.dev/config/
export default defineConfig({
root,
plugins: [
react(),
viteImagemin({
gifsicle: {
optimizationLevel: 7,
interlaced: false,
},
optipng: {
optimizationLevel: 7,
},
mozjpeg: {
quality: 20,
},
pngquant: {
quality: [0.8, 0.9],
speed: 4,
},
svgo: {
plugins: [
{
name: 'removeViewBox',
},
{
name: 'removeEmptyAttrs',
active: false,
},
],
},
webp: {
lossless: true,
quality: 65,
},
}),
createHtmlPlugin({
minify: true,
pages: [
{
entry: 'ts/main.tsx',
filename: 'index.html',
template: 'index.html',
},
{
entry: 'ts/about.tsx',
filename: 'about.html',
template: 'about.html',
}
]
})
],
build: {
outDir,
assetsDir,
assetsInlineLimit: 0,
emptyOutDir: true,
rollupOptions: {
// input: {
// main: resolve(root, 'index.html'),
// about: resolve(root, 'about', 'index.html')
// },
output: {
entryFileNames: `${assetsDir}/js/main.js`,
chunkFileNames: `${assetsDir}/js/[name].js`,
assetFileNames: ({ name = '' }) => {
if (/\.(gif|jpe?g|png|svg)$/.test(name)){
return `${assetsDir}/img/[name].[ext]`;
}
if (/\.css$/.test(name)) {
return `${assetsDir}/css/[name].[ext]`;
}
return `${assetsDir}/[name].[ext]`;
}
}
},
}
});