-
Notifications
You must be signed in to change notification settings - Fork 34
/
vite.config.js
69 lines (66 loc) · 1.75 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
// vite.config.js
import { defineConfig } from "vite";
// html partals
import injectHTML from "vite-plugin-html-inject";
// optimize images
import { ViteImageOptimizer } from 'vite-plugin-image-optimizer';
// Concatenate JavaScript files (like former Starter Kit)
import concat from '@vituum/vite-plugin-concat'
// Calculate paths
import FastGlob from 'fast-glob'
import path from 'node:path';
import { fileURLToPath } from 'node:url';
// Get all html files
const htmlFilesList = Object.fromEntries(
FastGlob.sync('src/*.html').map(file => [
// This remove `src/` as well as the file extension from each
// file, so e.g. src/nested/foo.js becomes nested/foo
path.relative(
'src',
file.slice(0, file.length - path.extname(file).length)
),
// This expands the relative paths to absolute paths, so e.g.
// src/nested/foo becomes /project/src/nested/foo.js
fileURLToPath(new URL(file, import.meta.url))
]));
const inputFilesList = {
...htmlFilesList,
'main': 'src/js/main.js',
}
export default defineConfig({
base: "./",
root: "src",
publicDir: "../public",
build: {
minify: "esbuild",
outDir: "../docs",
sourcemap: "inline",
emptyOutDir: true,
rollupOptions: {
input: inputFilesList,
output: {
sourcemap: true,
entryFileNames: ({name}) => {
if( name === 'main' ) {
return 'js/main.js';
}
// default value
// ref: https://rollupjs.org/configuration-options/#output-entryfilenames
return "[name].js";
},
},
},
},
server: {
open: "/index.html",
},
plugins: [
injectHTML(),
ViteImageOptimizer({
/* pass your config */
}),
concat({
input: ['main.js']
}),
],
});