-
Notifications
You must be signed in to change notification settings - Fork 2
/
vite.config.ts
111 lines (104 loc) · 3.01 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
// import path from "path";
import { defineConfig } from "vite";
import builtins from "builtin-modules";
import vue from "@vitejs/plugin-vue";
import { fileURLToPath, URL } from "node:url";
import process from "node:process";
import path from "path";
import fs from "fs/promises";
import manifest from "./manifest.json";
import dotenv from "dotenv";
import dotenvExpand from "dotenv-expand";
const env = dotenv.config();
dotenvExpand.expand(env);
const isWatch = process.argv.includes("--watch");
export default defineConfig(({ command }) => {
return {
plugins: [
vue(),
{
name: "postbuild-commands",
async closeBundle() {
if (!isWatch) return;
if (!process.env.OB_PLUGIN_DIST) {
console.log(
"为了更好的开发体验,你可以在 .env 中配置 OB_PLUGIN_DIST"
);
return;
}
const dist = process.env.OB_PLUGIN_DIST + manifest.id + "-dev";
await fs.mkdir(dist, { recursive: true });
const copy = async (src: string, dist: string) => {
await fs.copyFile(src, path.resolve(dist, src));
};
// do something
// copy file
await Promise.all([
await copy("./main.js", dist),
await copy("./styles.css", dist),
await copy("./manifest.json", dist),
await copy("./.hotreload", dist),
]);
console.log("复制结果到", dist);
},
},
],
build: {
target: "esnext",
sourcemap: isWatch ? "inline" : false,
commonjsOptions: {
ignoreTryCatch: false,
},
lib: {
entry: fileURLToPath(new URL("./src/starterIndex.ts", import.meta.url)),
formats: ["cjs"],
},
css: {},
rollupOptions: {
output: {
entryFileNames: "main.js",
assetFileNames: "styles.css",
exports: "named",
},
external: [
"obsidian",
"electron",
"codemirror",
"@codemirror/autocomplete",
"@codemirror/closebrackets",
"@codemirror/collab",
"@codemirror/commands",
"@codemirror/comment",
"@codemirror/fold",
"@codemirror/gutter",
"@codemirror/highlight",
"@codemirror/history",
"@codemirror/language",
"@codemirror/lint",
"@codemirror/matchbrackets",
"@codemirror/panel",
"@codemirror/rangeset",
"@codemirror/rectangular-selection",
"@codemirror/search",
"@codemirror/state",
"@codemirror/stream-parser",
"@codemirror/text",
"@codemirror/tooltip",
"@codemirror/view",
"@lezer/common",
"@lezer/lr",
"@lezer/highlight",
...builtins,
],
},
// Use root as the output dir
emptyOutDir: false,
outDir: ".",
},
resolve: {
alias: {
"@": path.resolve(__dirname, "src"),
},
},
};
});