-
-
Notifications
You must be signed in to change notification settings - Fork 5
/
Copy pathvite.config.js
96 lines (90 loc) · 2.98 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
96
import { globSync } from "glob";
import path, { resolve } from "path";
import handlebars from "vite-plugin-handlebars";
import { fileURLToPath } from "node:url";
import { config } from "./config.materialize";
let currentRoute = "";
function getMenuItem(item) {
// Has kids?
if (item.items) {
// active kids?
const kidsIds = item.items.map((el) => el.id);
const kidsPages = config.pages.filter((page) => kidsIds.includes(page.id));
const hasActiveKid = kidsPages.some(
(kid) => currentRoute === "/" + kid.url
);
const activeClass = hasActiveKid ? "active" : "";
return `<li>
<ul class="collapsible collapsible-accordion">
<li class="${activeClass}">
<a class="collapsible-header waves-effect">
${item.icon ? `<span class="material-icons">${item.icon}</span>` : ""}
${item.name || ""}
</a>
<div class="collapsible-body">
<ul>
${item.items.map((itm) => getMenuItem(itm)).join("")}
</ul>
</div>
</li>
</ul>
</li>`;
}
// Merge
let page = {};
if (item.id) {
page = config.pages.find((page) => page.id === item.id);
}
const merged = { ...page, ...item };
// active
const isActive = currentRoute === "/" + merged.url;
const activeClass = isActive ? "active" : "";
return `<li class="${activeClass}">
<a href="${merged.url || "#"}">
${merged.icon ? `<span class="material-icons">${merged.icon}</span>` : ""}
${merged.name || "?"}</a>
</li>`;
}
export default {
base: "./",
resolve: {
alias: {
'@materializecss/materialize/sass': path.resolve(__dirname, './packages/materialize/sass/'),
'@materializecss/materialize': path.resolve(__dirname, './packages/materialize/src/')
}
},
plugins: [
handlebars({
context(pagePath) {
currentRoute = pagePath;
const searchUrl = pagePath.substring(1);
const index = config.pages.find((page) => page.id === "index");
const page = config.pages.find((page) => page.url === searchUrl);
// Use default Values if they are not set
if (page && !page.description) page.description = index.description;
return { page, config };
},
helpers: {
getmenu: function(item) {
return getMenuItem(item);
},
},
partialDirectory: resolve(__dirname, "partials"),
}),
],
build: {
rollupOptions: {
//this is needed for "vite publish" to include all html files, not only the index.
input: Object.fromEntries(
globSync("*.html").map((file) => [
// This remove the file extension from each
// file, so e.g. nested/foo.js becomes nested/foo
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)),
])
),
},
},
};