-
Notifications
You must be signed in to change notification settings - Fork 107
/
vite.config.ts
128 lines (122 loc) · 5.41 KB
/
vite.config.ts
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
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
import { defineConfig } from "vite";
import solidPlugin from "vite-plugin-solid";
import fs from "fs";
import sharp from "sharp";
import {
base_profile as bp,
extended_profile as ep,
webpage_config as c,
} from "./src/config";
export default defineConfig({
plugins: [solidPlugin()],
server: {
port: 3000,
},
build: {
target: "esnext",
rollupOptions: {
plugins: [
{
name: "picture-webp",
async writeBundle() {
const folder = "dist";
const files = fs
.readdirSync(folder)
.filter(
(f) =>
f.toLowerCase().endsWith(".png") ||
f.toLowerCase().endsWith(".jpg")
);
const promises = files.map((name) =>
sharp(fs.readFileSync(folder + "/" + name))
.resize({
fit: sharp.fit.contain,
width: name.includes("profile")
? 150
: name.includes("banner")
? 455
: undefined,
height: name.includes("banner")
? 130
: undefined,
})
.toFile(folder + "/" + name)
.then(async () => {
await sharp(
fs.readFileSync(folder + "/" + name)
)
.toFormat("webp", { quality: 70 })
.toFile(
folder +
"/" +
name.replace(
/\.[^/.]+$/,
".webp"
)
)
.then(() => {})
.catch((e) =>
console.log(
"Failed converting",
name,
e,
"skipping..."
)
);
console.log(folder + "/" + name, "-> webp");
})
.catch((e) =>
console.log(
"Failed converting",
name,
e,
"skipping..."
)
)
);
Promise.all(promises)
.then(() => {})
.catch((e) => console.error(e));
},
},
{
name: "MetaTag",
async writeBundle() {
let html = `
<title>${c.title}</title>
<meta name="description" content="${c.desc}">
<meta name="keywords" content="${c.keywords}">
<meta property="og:title" content="${c.title}">
<meta property="og:site_name" content="${c.title}">
<meta property="og:description" content="${c.desc}">
<meta property="og:updated_time" content="${Date.now()}" />
<meta property="og:image:type" content="image/png" />
<meta property="og:image:alt" content="Profile" />
<meta property="profile:first_name" content="${
bp.first_name
}">
<meta property="profile:last_name" content="${
bp.last_name
}">
`;
if (ep.username) {
html += `
<meta property="profile:username" content="${ep.username}">
`;
}
if (ep.gender) {
html += `
<meta property="profile:gender" content="${ep.gender}">
`;
}
const fileData = fs
.readFileSync("dist/index.html")
.toString()
.replace(/<!-- BUILD_REPLACE -->/g, html);
fs.writeFileSync("dist/index.html", fileData);
},
},
],
},
},
});