-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathvite.config.js
More file actions
55 lines (51 loc) · 1.6 KB
/
Copy pathvite.config.js
File metadata and controls
55 lines (51 loc) · 1.6 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
import { defineConfig } from "vite";
import react from "@vitejs/plugin-react";
import tailwindcss from "@tailwindcss/vite";
import { convertTailwind } from "./netlify/lib/tailwindCompiler.mjs";
const tailwindConversionApi = () => ({
name: "codearc-tailwind-conversion-api",
enforce: "post",
configureServer(server) {
server.middlewares.use(async (request, response, next) => {
if (
request.url !== "/.netlify/functions/convert-tailwind" ||
request.method !== "POST"
) {
next();
return;
}
let body = "";
for await (const chunk of request) {
body += chunk;
if (new TextEncoder().encode(body).byteLength > 250000) {
response.statusCode = 413;
response.setHeader("content-type", "application/json");
response.end(JSON.stringify({ error: "Request body is too large." }));
return;
}
}
try {
const result = await convertTailwind(JSON.parse(body).html);
response.statusCode = 200;
response.setHeader("content-type", "application/json");
response.end(JSON.stringify(result));
} catch (error) {
response.statusCode = 400;
response.setHeader("content-type", "application/json");
response.end(
JSON.stringify({
error:
error instanceof Error ? error.message : "Conversion failed.",
}),
);
}
});
},
});
export default defineConfig({
plugins: [react(), tailwindcss(), tailwindConversionApi()],
define: {
"process.env": {},
"process.platform": null,
},
});