-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathvite.config.ts
49 lines (44 loc) · 1.24 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
import { defineConfig, Plugin } from "vite";
import vue from "@vitejs/plugin-vue";
import path from "path";
import { readFileSync } from "fs";
const bufferLoader: Plugin = {
name: "buffer-loader",
transform(_, id) {
const [path, query] = id.split("?");
if (query != "buffer") return null;
const data = readFileSync(path);
const base64 = data.toString("base64");
return `
function decodeBase64(base64) {
const binaryString = atob(base64);
const bytes = new Uint8Array(binaryString.length);
for (let i = 0; i < binaryString.length; i++) {
bytes[i] = binaryString.charCodeAt(i);
}
return bytes;
}
export default decodeBase64('${base64}');`;
},
};
// https://vite.dev/config/
export default defineConfig({
build: {
// It only includes vite.svg which we don't need in the built output.
copyPublicDir: false,
lib: {
entry: path.resolve(__dirname, "src/main.ts"),
formats: ["es"],
},
},
define: {
// Required in library mode to get rid of process.env in the built file.
"process.env.NODE_ENV": '"production"',
},
plugins: [vue(), bufferLoader],
resolve: {
alias: {
"@assets": path.resolve(__dirname, "src/assets"),
},
},
});