-
Notifications
You must be signed in to change notification settings - Fork 0
/
vite.config.js
63 lines (55 loc) · 1.79 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
import { glob } from 'glob';
import { resolve } from 'path';
import { defineConfig } from 'vite';
import { createHtmlPlugin } from 'vite-plugin-html';
const entries = glob.sync('./pages/**/*.html').reduce((acc, path) => {
const name = path.split('/').pop().split('.').shift();
acc[name] = path;
return acc;
}, {});
entries['main'] = resolve(__dirname, 'index.html');
export default defineConfig({
optimizeDeps: {
entries: Object.keys(entries),
},
plugins: [createHtmlPlugin()],
build: {
target: 'esnext',
rollupOptions: {
input: entries,
output: {
assetFileNames: chunkInfo => {
let outDir = '';
// Fonts
if (/(ttf|woff|woff2|eot)$/.test(chunkInfo.name)) {
outDir = 'fonts';
}
// SVG
if (/svg$/.test(chunkInfo.name)) {
outDir = 'images/svg';
}
// Images
if (/(png|jpg|jpeg|gif|webp)$/.test(chunkInfo.name)) {
outDir = 'images';
}
// JS
if (/js$/.test(chunkInfo.name)) {
outDir = 'scripts';
}
// CSS
if (/css$/.test(chunkInfo.name)) {
outDir = 'styles';
}
return `${outDir}/[name][extname]`;
},
chunkFileNames: 'scripts/[name]-[hash].js',
entryFileNames: 'scripts/[name]-[hash].js',
},
},
chunkSizeWarningLimit: 1500, // 1500KiB
},
server: {
port: 6500,
open: true,
},
});