forked from SheepChef/Abracadabra
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathvite.config.js
More file actions
45 lines (42 loc) · 1.35 KB
/
vite.config.js
File metadata and controls
45 lines (42 loc) · 1.35 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
// vite.config.js
import { defineConfig } from "vite";
import fs from "fs";
import path from "path";
let outDir = "";
let configStore;
export default defineConfig({
// 配置选项
build: {
outDir: "dist", // 将打包后的文件输出到 dist 目录
minify: "eslint", // 使用 terser 进行压缩
lib: {
entry: "./src/javascript/main.js",
name: "abracadabra-cn",
fileName: "abracadabra-cn",
},
},
plugins: [
{
name: "Abracadabra-Javy-Artifact",
apply: "build", // 只在生产构建时生效
configResolved(config) {
// 保存最终输出目录路径
outDir = path.resolve(config.root, config.build.outDir);
configStore = config;
},
async writeBundle() {
// 自定义内容(这里可以修改为你需要追加的内容)
const AppendContentPath = path.join(
configStore.root,
"JavyInputAppendix.js"
);
const appendContent = fs.readFileSync(AppendContentPath, "utf8");
const TargetContentPath = path.join(outDir, "abracadabra-cn.js");
const TargetContent = fs.readFileSync(TargetContentPath, "utf8");
//创建全新文件
const newFilePath = path.join(outDir, "abracadabra-cn-javy.js");
fs.writeFileSync(newFilePath, `${TargetContent}${appendContent}`);
},
},
],
});