-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathvite.daemon.config.ts
More file actions
107 lines (91 loc) · 2.82 KB
/
vite.daemon.config.ts
File metadata and controls
107 lines (91 loc) · 2.82 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
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
/* eslint-disable node/prefer-global/process */
import { resolve } from "node:path"
import fg from "fast-glob"
import minimist from "minimist"
import livereload from "rollup-plugin-livereload"
import {
defineConfig,
loadEnv,
} from "vite"
import { viteStaticCopy } from "vite-plugin-static-copy"
import zipPack from "vite-plugin-zip-pack"
const pluginInfo = require("./plugin.json")
export default defineConfig(({
mode,
}) => {
console.log('mode=>', mode)
const env = loadEnv(mode, process.cwd())
const {
VITE_SIYUAN_WORKSPACE_PATH,
} = env
console.log('env=>', env)
const siyuanWorkspacePath = VITE_SIYUAN_WORKSPACE_PATH
let devDistDir = './dev'
if (!siyuanWorkspacePath) {
console.log("\nSiyuan workspace path is not set.")
} else {
console.log(`\nSiyuan workspace path is set:\n${siyuanWorkspacePath}`)
devDistDir = `${siyuanWorkspacePath}/data/plugins/${pluginInfo.name}`
}
console.log(`\nPlugin will build to:\n${devDistDir}`)
const args = minimist(process.argv.slice(2))
const isWatch = args.watch || args.w || false
const distDir = (isWatch || mode === "development") ? devDistDir : "./dist"
console.log()
console.log("isWatch=>", isWatch)
console.log("distDir=>", distDir)
return {
resolve: {
alias: {
"@": resolve(__dirname, "src"),
},
},
plugins: [],
// https://github.com/vitejs/vite/issues/1930
// https://vitejs.dev/guide/env-and-mode.html#env-files
// https://github.com/vitejs/vite/discussions/3058#discussioncomment-2115319
// 在这里自定义变量
define: {
"process.env.DEV_MODE": `"${isWatch}"`,
"process.env.NODE_ENV": JSON.stringify(process.env.NODE_ENV),
},
build: {
// 输出路径
outDir: distDir,
emptyOutDir: !isWatch,
// 构建后是否生成 source map 文件
sourcemap: false,
// 设置为 false 可以禁用最小化混淆
// 或是用来指定是应用哪种混淆器
// boolean | 'terser' | 'esbuild'
// 不压缩,用于调试
minify: !isWatch,
lib: {
// Could also be a dictionary or array of multiple entry points
entry: resolve(__dirname, "src/daemon.ts"),
// the proper extensions will be added
fileName: "daemon",
formats: ["umd"],
name: "pseudocodeDaemon",
},
rollupOptions: {
plugins: [],
// make sure to externalize deps that shouldn't be bundled
// into your library
external: ["siyuan", "process"],
output: {
entryFileNames: "[name].js",
assetFileNames: (assetInfo) => {
if (assetInfo.name === "style.css") {
return "index.css"
}
return assetInfo.name
},
globals: {
siyuan: "siyuan",
},
},
},
},
}
})