generated from nguyenbn7/vite-vanilla-starter
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathvite.config.js
50 lines (42 loc) · 1.1 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
import { defineConfig, loadEnv } from 'vite';
import path from 'path';
import fs from 'fs';
function getHtmlEntries() {
const pagesDir = path.resolve(__dirname, 'src');
/** @type {{[name: string]: string}} */
const entries = {};
// Read all files in the directory
const files = fs.readdirSync(pagesDir, {
recursive: true,
encoding: 'utf-8',
});
// Filter out HTML files
const htmlFiles = files.filter((file) => file.endsWith('.html'));
// Create entries for each HTML file
htmlFiles.forEach((file) => {
const key =
file
.replace(/\.[^/.]+$/, '')
.replace(/\\/g, '/')
.split('/')
.slice(0, -1)
.join('/') || 'index';
entries[key] = path.resolve(pagesDir, file);
});
return entries;
}
// @ts-ignore
export default ({ mode }) => {
process.env = { ...process.env, ...loadEnv(mode, process.cwd()) };
return defineConfig({
base: process.env.VITE_GITHUB_REPO ?? '/',
root: './src',
build: {
outDir: '../dist',
emptyOutDir: true,
rollupOptions: {
input: getHtmlEntries(),
},
},
});
};