-
Notifications
You must be signed in to change notification settings - Fork 0
/
vite.config.js
118 lines (112 loc) · 2.26 KB
/
vite.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
import legacy from '@vitejs/plugin-legacy';
import autoprefixer from 'autoprefixer';
import Path from 'path';
import { defineConfig } from 'vite';
import { ViteAliases } from 'vite-aliases';
import { ViteImageOptimizer } from 'vite-plugin-image-optimizer';
import pages from './src/pages/pages.config';
const DEFAULT_OPTIONS = {
test: /\.(jpe?g|png|tiff|webp|svg|avif)$/i,
exclude: undefined,
include: undefined,
excludePublic: ['./public/**/*'],
includePublic: false,
logStats: true,
svg: {
multipass: true,
plugins: [
{
name: 'preset-default',
params: {
overrides: {
cleanupNumericValues: false,
removeViewBox: false,
},
cleanupIDs: {
minify: false,
remove: false,
},
convertPathData: false,
},
},
'sortAttrs',
{
name: 'addAttributesToSVGElement',
params: {
attributes: [{ xmlns: 'http://www.w3.org/2000/svg' }],
},
},
],
},
png: {
quality: 100,
palette: true,
},
jpeg: {
quality: 95,
},
jpg: {
quality: 95,
},
tiff: {
quality: 100,
},
gif: {},
webp: {
lossless: true,
},
avif: {
lossless: true,
},
};
const pagesInput = {};
pages.forEach(page => {
pagesInput[page.name] = page.path;
});
export default defineConfig({
root: Path.resolve(__dirname, './src'),
base: './',
publicDir: '../public',
css: {
postcss: {
plugins: [autoprefixer],
},
devSourcemap: true,
},
plugins: [
ViteAliases(),
ViteImageOptimizer({
DEFAULT_OPTIONS,
}),
legacy({
targets: ['> 0.5%', 'last 2 versions', 'Firefox ESR', 'not dead'],
}),
],
build: {
emptyOutDir: true,
outDir: Path.resolve(__dirname, './build'),
rollupOptions: {
output: {
assetFileNames: assetInfo => {
let info = assetInfo.name.split('.');
let extType = info[info.length - 1];
if (/svg|png|jpe?g|tiff|gif|webp|avif|bmp|ico/i.test(extType)) {
extType = 'images';
} else if (/eot|otf|ttf|fnt|woff|woff2/.test(extType)) {
extType = 'fonts';
} else if (/css/.test(extType)) {
extType = 'css';
}
return `assets/${extType}/[name]-[hash][extname]`;
},
entryFileNames: 'assets/js/[name]-[hash].js',
chunkFileNames: 'assets/js/[name]-[hash].js',
},
},
},
server: {
hmr: true,
port: 3000,
host: '0.0.0.0',
},
});