forked from WTPieh/SakuraTool
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathvite.config.js
More file actions
85 lines (79 loc) · 2.7 KB
/
vite.config.js
File metadata and controls
85 lines (79 loc) · 2.7 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
import { defineConfig } from "vite";
import react from "@vitejs/plugin-react";
import { resolve } from "path";
import fs from "fs-extra";
export default defineConfig({
plugins: [
react(),
{
name: "copy-extension-files",
buildStart: () => {
// Ensure dist directory exists
fs.ensureDirSync("dist");
},
writeBundle: () => {
// Move popup.html to dist/
const popupSrc = "dist/src/popup.html";
const popupDest = "dist/popup.html";
if (fs.existsSync(popupSrc)) {
fs.moveSync(popupSrc, popupDest, { overwrite: true });
fs.removeSync("dist/src");
console.log("Moved popup.html to dist and removed dist/src");
}
// Copy manifest.json from src
fs.copyFileSync("src/manifest.json", "dist/manifest.json");
// Copy icons from src/assets/icons to dist/assets/icons
if (fs.existsSync("src/assets/icons")) {
fs.ensureDirSync("dist/assets/icons");
fs.copySync("src/assets/icons", "dist/assets/icons", {
overwrite: true,
});
console.log("Copied icons to dist/assets/icons");
} else {
console.warn("src/assets/icons directory not found, skipping...");
}
// Copy _locales from src/_locales to dist/_locales
if (fs.existsSync("src/_locales")) {
fs.copySync("src/_locales", "dist/_locales", { overwrite: true });
console.log("Copied _locales to dist/_locales");
} else {
console.warn("src/_locales directory not found, skipping...");
}
// Copy utils/script.js to dist/utils/script.js
if (fs.existsSync("src/utils/script.js")) {
fs.ensureDirSync("dist/utils");
fs.copyFileSync("src/utils/script.js", "dist/utils/script.js");
console.log("Copied utils/script.js to dist/utils");
} else {
console.warn("src/utils/script.js not found, skipping...");
}
console.log("Build complete! Extension ready in dist/");
},
},
],
build: {
outDir: "dist",
rollupOptions: {
input: {
popup: resolve(__dirname, "src/popup.html"),
background: resolve(__dirname, "src/background.js"),
},
output: {
entryFileNames: "[name].js",
chunkFileNames: "[name].js",
assetFileNames: "[name].[ext]",
},
},
},
resolve: {
alias: {
"@": resolve(__dirname, "src"),
"@components": resolve(__dirname, "src/components"),
"@utils": resolve(__dirname, "src/utils"),
"@types": resolve(__dirname, "src/types"),
"@assets": resolve(__dirname, "src/assets"),
},
},
publicDir: "src/assets",
copyPublicDir: true,
});