-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathvite.config.js
More file actions
59 lines (50 loc) · 1.43 KB
/
vite.config.js
File metadata and controls
59 lines (50 loc) · 1.43 KB
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
import { defineConfig } from 'vite';
import { resolve } from 'path'
import glob from 'fast-glob'
// Grab all HTML files inside src (including subfolders)
const htmlFiles = glob.sync('./src/**/*.html')
export default defineConfig({
base: './',
root: resolve(__dirname, 'src'), // ✅ keeps dev server working
server: {
host: true,
port: 3000,
hot: true,
open: true,
},
css: {
preprocessorOptions: {
scss: {
},
}
},
build: {
outDir: resolve(__dirname, 'dist'), // ✅ output outside src
emptyOutDir: true,
rollupOptions: {
input: htmlFiles.length
? Object.fromEntries(
htmlFiles.map(file => [
file.replace(/^\.\/src\//, '').replace(/\.html$/, ''),
resolve(__dirname, file),
])
)
: resolve(__dirname, 'src/index.html'),
output: {
chunkFileNames: 'assets/js/[name].js',
entryFileNames: 'assets/js/[name].js',
assetFileNames: ({name}) => {
if (/\.(gif|jpe?g|png|svg)$/.test(name ?? '')){
return 'assets/images/[name][extname]';
}
if (/\.css$/.test(name ?? '')) {
return 'assets/css/[name][extname]';
}
// default value
// ref: https://rollupjs.org/guide/en/#outputassetfilenames
return 'assets/[name][extname]';
},
},
},
},
});