This repository was archived by the owner on Sep 2, 2026. It is now read-only.
Repository navigation
Expand file tree
/
Copy pathastro.config.mjs
More file actions
82 lines (74 loc) · 2.33 KB
/
Copy pathastro.config.mjs
File metadata and controls
82 lines (74 loc) · 2.33 KB
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
import fs from "node:fs";
import path from "node:path";
import { fileURLToPath } from "node:url";
import react from "@astrojs/react";
import tailwindcss from "@tailwindcss/vite";
import { defineConfig } from "astro/config";
import { transform } from "esbuild";
const rootDirectory = path.dirname(fileURLToPath(import.meta.url));
const cdnDirectory = path.join(rootDirectory, "cdn");
const outputDirectory = path.join(rootDirectory, "dist");
function staticCdnPlugin() {
return {
name: "vanillasquared-static-cdn",
configureServer(server) {
server.middlewares.use("/cdn", (request, response, next) => {
const requestUrl = new URL(request.url ?? "/", "http://localhost");
if (requestUrl.searchParams.has("import")) {
next();
return;
}
const requestPath = decodeURIComponent(requestUrl.pathname);
const absolutePath = path.resolve(cdnDirectory, `.${requestPath}`);
if (!absolutePath.startsWith(`${cdnDirectory}${path.sep}`) || !fs.existsSync(absolutePath) || !fs.statSync(absolutePath).isFile()) {
next();
return;
}
fs.createReadStream(absolutePath).pipe(response);
});
},
writeBundle() {
fs.cpSync(cdnDirectory, path.join(outputDirectory, "cdn"), { recursive: true });
},
};
}
function jsxJavaScriptPlugin() {
return {
name: "vanillasquared-jsx-javascript",
enforce: "pre",
async transform(code, id) {
const [fileId] = id.split(/[?#]/, 1);
const normalizedId = fileId.replaceAll("\\", "/");
if (!normalizedId.includes("/src/") || !normalizedId.endsWith(".js")) return undefined;
const result = await transform(code, {
loader: "jsx",
jsx: "automatic",
sourcefile: fileId,
sourcemap: true,
});
return { code: result.code, map: result.map };
},
};
}
export default defineConfig({
output: "static",
integrations: [react()],
redirects: {
"/modlicence": "/license/mod",
"/licence": "/license/website",
},
vite: {
plugins: [jsxJavaScriptPlugin(), tailwindcss(), staticCdnPlugin()],
optimizeDeps: {
rolldownOptions: {
moduleTypes: { ".js": "jsx" },
},
},
resolve: {
alias: {
"@": path.join(rootDirectory, "src"),
"@cdn": path.join(rootDirectory, "cdn"),
},
},
},
});