-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathvite.config.js
95 lines (92 loc) · 2.26 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
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
import { defineConfig } from "vite";
import path from "path";// https://nodejs.org/api/path.html
import globule from "globule"; // https://www.npmjs.com/package/globule
import eslint from "@nabla/vite-plugin-eslint";
import vitePluginPugStatic from "@macropygia/vite-plugin-pug-static";
import viteImagemin from "vite-plugin-imagemin";
import browserslistToEsbuild from "browserslist-to-esbuild";
import checker from "vite-plugin-checker";
const inputs = {};
const documents = globule.find([`./src/**/*.html`, `./src/**/*.pug`], {
ignore: [`./src/html/**/_*.html`, `./src/pug/**/_*.pug`],
});
documents.forEach((document) => {
const fileName = document.replace(`./src/`, "");
const key = path.parse(document).name;
inputs[key] = path.resolve(__dirname, "src", fileName);
});
export default defineConfig({
root: "src",
server: {
host: true,
port: 3000
},
esbuild: {
supported: {
"top-level-await": true
}
},
build: {
outDir: "../dist",
emptyOutDir: true,
target: browserslistToEsbuild(),
minify: false,
rollupOptions: {
input: { ...inputs },
output: {
entryFileNames: `assets/js/[name].js`,
chunkFileNames: `assets/js/[name].js`,
assetFileNames: (assetInfo) => {
if (/\.( gif|jpeg|jpg|png|svg|webp| )$/.test(assetInfo.name)) {
return `assets/images/[name].[ext]`;
}
if (/\.css$/.test(assetInfo.name)) {
return `assets/css/[name].[ext]`;
}
return 'assets/[name].[ext]';
}
}
}
},
plugins: [
eslint({
eslintOptions: {
fix: true,
}
}),
checker({
typescript: true,
}),
vitePluginPugStatic({
buildOptions: { basedir: "src" },
serveOptions: { basedir: "src" }
}),
viteImagemin({
gifsicle: {
optimizationLevel: 7,
interlaced: false,
},
optipng: {
optimizationLevel: 7,
},
mozjpeg: {
quality: 20,
},
pngquant: {
quality: [0.8, 0.9],
speed: 4,
},
svgo: {
plugins: [
{
name: "removeViewBox",
},
{
name: "removeEmptyAttrs",
active: false,
},
],
},
})
]
})