-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathvite.config.js
77 lines (74 loc) · 1.88 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
import { defineConfig } from "vite";
import path, { resolve } from "path";
import globule from "globule";
import eslint from "@nabla/vite-plugin-eslint";
import handlebar from "vite-plugin-handlebars";
import pluginRewriteAll from "vite-plugin-rewrite-all";
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);
});
const pageData = {
"/index.html": {
isHome: true,
title: "Main Page",
},
"/sub.html": {
isHome: false,
title: "Sub Page",
},
};
export default defineConfig({
root: "./src",
base: "./",
public: "./public/",
server: {
host: true,
port: 5500,
middlewareMode: false,
},
build: {
outDir: "../dist",
assetsDir: "assets",
emptyOutDir: true,
manifest: true,
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/style.css`;
}
if (/ttf|otf|eot|woff|woff2/i.test(assetInfo.name)) {
return `assets/font/[name].[ext]`;
}
return "assets/[name].[ext]";
},
},
},
},
plugins: [
eslint({
eslintOptions: {
fix: true,
},
}),
handlebar({
partialDirectory: resolve(__dirname, "./src/components"),
context(pagePath) {
return pageData[pagePath];
},
}),
pluginRewriteAll(),
],
});