-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathvite.config.js
More file actions
49 lines (45 loc) · 1.17 KB
/
Copy pathvite.config.js
File metadata and controls
49 lines (45 loc) · 1.17 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
import { Buffer } from "node:buffer";
import { readFile } from "node:fs/promises";
import { defineConfig } from "vite";
function rescriptInputSourceMaps() {
return {
name: "rescript-input-source-maps",
enforce: "pre",
async load(id) {
if (!id.endsWith(".js") || !id.includes("/src/")) {
return null;
}
try {
const code = await readFile(id, "utf8");
let map;
try {
map = JSON.parse(await readFile(`${id}.map`, "utf8"));
} catch {
const inlineMap = code.match(
/\/\/# sourceMappingURL=data:application\/json;base64,([A-Za-z0-9+/=]+)\s*$/,
);
if (inlineMap == null) {
return null;
}
map = JSON.parse(Buffer.from(inlineMap[1], "base64").toString("utf8"));
}
if (process.env.DEBUG_RESCRIPT_MAPS === "1") {
console.log(`[rescript-input-source-maps] ${id}`);
}
return { code, map };
} catch {
return null;
}
}
};
}
export default defineConfig({
plugins: [rescriptInputSourceMaps()],
server: {
port: 5173,
strictPort: false
},
build: {
sourcemap: true
}
});