-
Notifications
You must be signed in to change notification settings - Fork 2
/
vite.config.ts
152 lines (143 loc) · 4.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
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
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
import os from "os";
import fs from "fs";
import path from "path";
import { defineConfig } from "vite";
import vue from "@vitejs/plugin-vue";
import webExtension from "@samrum/vite-plugin-web-extension";
import VueI18nPlugin from "@intlify/unplugin-vue-i18n/vite";
import { nodePolyfills } from "vite-plugin-node-polyfills";
import vuetify from "vite-plugin-vuetify";
import generateFile from "vite-plugin-generate-file";
import git from "git-rev-sync";
import pkg from "./package.json";
const siteIcons = fs.readdirSync("public/icons/site");
// https://vitejs.dev/config/
export default defineConfig({
root: "src",
publicDir: "../public",
build: {
outDir: "../dist",
emptyOutDir: true,
rollupOptions: {
output: {
// Vite 默认的 chunkFileNames, entryFileNames 会将所有的产物都放在 assets 下,这里我们根据需要进行调整至分别的目录
chunkFileNames: (chunkInfo) => {
// 特殊情况下 facadeModuleId 可能为 null,这时我们使用 moduleIds 的最后一个作为 chunkName
const chunkName =
chunkInfo.facadeModuleId || chunkInfo.moduleIds.slice(-1)[0];
if (
/[\\/]src[\\/]packages[\\/](downloader|backupServer|site).+\.ts/.test(
chunkName,
) ||
/[\\/]src[\\/]entries[\\/].+\.vue/.test(chunkName)
) {
const name = chunkName
.replace(/^.+?[\\/]src[\\/]/, "")
.replace(/\..+?$/, "");
return `${name}-[hash].js`;
}
return "assets/[name]-[hash].js"; // vite default
},
entryFileNames: (chunkInfo) => {
if (chunkInfo.name.includes("entries")) {
return "[name]-[hash].js";
}
return "assets/[name]-[hash].js"; // vite default
},
},
},
},
plugins: [
nodePolyfills({
include: ["buffer", "path"],
globals: {
Buffer: true,
},
}),
vue(),
vuetify(),
VueI18nPlugin({
strictMessage: false,
include: [path.resolve(__dirname, "./src/locales/**")],
}),
webExtension({
manifest: {
manifest_version: 3,
version: `${pkg.version}.${git.count() % 65535}`,
name: "__MSG_extName__",
description: "__MSG_extDesc__",
default_locale: "en",
homepage_url: "https://github.com/ronggang/PT-Plugin-Plus",
icons: {
"16": "icons/logo/16.png",
"19": "icons/logo/19.png",
"64": "icons/logo/64.png",
"128": "icons/logo/128.png",
},
minimum_chrome_version: "120",
action: {
default_icon: {
"16": "icons/logo/16.png",
"19": "icons/logo/19.png",
"64": "icons/logo/64.png",
"128": "icons/logo/128.png",
},
default_title: "__MSG_extName__",
},
background: {
service_worker: "entries/background/main.ts",
},
options_ui: {
page: "entries/options/index.html",
open_in_tab: true,
},
permissions: [
"activeTab",
"alarms",
"clipboardWrite",
"contextMenus",
"cookies",
"notifications",
"scripting",
"storage",
"unlimitedStorage",
"offscreen",
],
host_permissions: ["*://*/*"],
},
additionalInputs: {
html: ["entries/offscreen/offscreen.html"],
},
}),
generateFile([
{
type: "json",
output: "build_info.json",
data: {
buildAt: Date.now(),
gitVersion: {
short: git.short(__dirname),
long: git.long(__dirname),
date: git.date(),
count: git.count(),
branch: git.branch(__dirname),
}, // Add git detail in manifest when build
buildOs: {
arch: os.arch(),
platform: os.platform(),
release: os.release(),
type: os.type(),
},
siteIcons,
},
},
]),
],
resolve: {
alias: {
"~": path.resolve(__dirname, "./src"),
"@": path.resolve(__dirname, "./src/entries"),
"@ptd": path.resolve(__dirname, "./src/packages"),
},
},
});