-
-
Notifications
You must be signed in to change notification settings - Fork 67
/
vite.config.ts
58 lines (52 loc) · 1.48 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
import fs from 'fs';
import path, { resolve } from 'path';
import { defineConfig } from 'vite';
const getInputVite: () => { [key: string]: string } = () => {
const pages: string[] = [];
function fromDir(startPath: string, filter: string): void {
if (!fs.existsSync(startPath)) {
console.log('no dir ', startPath);
return;
}
const files: string[] = fs.readdirSync(startPath);
for (let i = 0; i < files.length; i++) {
const filename: string = path.join(startPath, files[i]);
const stat: fs.Stats = fs.lstatSync(filename);
if (stat.isDirectory()) {
fromDir(filename, filter);
} else if (filename.endsWith(filter)) {
pages.push(filename);
}
}
}
fromDir('./demo/pages', '.html');
return pages.reduce((acc: { [key: string]: string }, current: string, index: number) => {
acc['0'] = resolve(__dirname, 'demo', 'index.html');
acc[(index + 1).toString()] = resolve(__dirname, current);
return acc;
}, {});
};
export default defineConfig({
root: './demo',
build: {
assetsDir: '',
outDir: 'build',
target: 'ES6',
cssCodeSplit: true,
minify: 'terser',
rollupOptions: {
input: getInputVite(),
},
},
server: {
port: 5173,
},
resolve: {
alias: {
'@': resolve(__dirname, './'),
'@package': resolve(__dirname, './package'),
'@src': resolve(__dirname, './package/src'),
'@scripts': resolve(__dirname, './package/src/scripts'),
},
},
});