-
Notifications
You must be signed in to change notification settings - Fork 50
Expand file tree
/
Copy pathvite.config.ts
More file actions
177 lines (170 loc) · 4.24 KB
/
vite.config.ts
File metadata and controls
177 lines (170 loc) · 4.24 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
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
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
// import MillionLint from "@million/lint";
import { exec } from "node:child_process";
import { existsSync } from "node:fs";
import { resolve } from "node:path";
import react from "@vitejs/plugin-react";
import jotaiDebugLabel from "jotai/babel/plugin-debug-label";
import jotaiReactRefresh from "jotai/babel/plugin-react-refresh";
import ConditionalCompile from "unplugin-preprocessor-directives/vite";
import { defineConfig, type Plugin } from "vite";
import i18nextLoader from "vite-plugin-i18next-loader";
import { VitePWA } from "vite-plugin-pwa";
// 由于这个插件会除去 Source Map 注释,所以考虑移除
// https://github.com/Menci/vite-plugin-top-level-await/issues/34
// import topLevelAwait from "vite-plugin-top-level-await";
import wasm from "vite-plugin-wasm";
import svgLoader from "vite-svg-loader";
const AMLL_LOCAL_EXISTS = existsSync(
resolve(__dirname, "../applemusic-like-lyrics"),
);
const ReactCompilerConfig = {
target: "19",
};
process.env.AMLL_LOCAL_EXISTS = AMLL_LOCAL_EXISTS ? "true" : "false";
const plugins: Plugin[] = [
ConditionalCompile(),
// topLevelAwait(),
// MillionLint.vite(),
react({
babel: {
presets: ["jotai/babel/preset"],
plugins: [
["babel-plugin-react-compiler", ReactCompilerConfig],
jotaiDebugLabel,
jotaiReactRefresh,
],
},
}),
svgLoader(),
wasm(),
i18nextLoader({
paths: ["./locales"],
namespaceResolution: "basename",
}),
{
name: "buildmeta",
async resolveId(id) {
if (id === "virtual:buildmeta") {
return id;
}
},
async load(id) {
if (id === "virtual:buildmeta") {
let gitCommit = "unknown";
try {
gitCommit = await new Promise<string>((resolve, reject) =>
exec("git rev-parse HEAD", (err, stdout) => {
if (err) {
reject(err);
} else {
resolve(stdout.trim());
}
}),
);
} catch {}
return `
export const BUILD_TIME = "${new Date().toISOString()}";
export const GIT_COMMIT = "${gitCommit}";
`;
}
},
},
VitePWA({
injectRegister: null,
disable: !!process.env.TAURI_PLATFORM,
workbox: {
globPatterns: ["**/*.{js,css,html,wasm}"],
maximumFileSizeToCacheInBytes: 8 * 1024 * 1024,
},
manifest: {
name: "Apple Music-like lyrics TTML Tool",
id: "amll-ttml-tool",
short_name: "AMLL TTML Tool",
description: "一个用于 Apple Music 的逐词歌词 TTML 编辑和时间轴工具",
theme_color: "#18a058",
icons: [
{
src: "./icons/Square30x30Logo.png",
sizes: "30x30",
type: "image/png",
},
{
src: "./icons/Square44x44Logo.png",
sizes: "44x44",
type: "image/png",
},
{
src: "./icons/Square71x71Logo.png",
sizes: "71x71",
type: "image/png",
},
{
src: "./icons/Square89x89Logo.png",
sizes: "89x89",
type: "image/png",
},
{
src: "./icons/Square107x107Logo.png",
sizes: "107x107",
type: "image/png",
},
{
src: "./logo.png",
sizes: "1024x1024",
type: "image/png",
},
{
src: "./logo.svg",
sizes: "128x128",
type: "image/svg",
},
],
},
}),
];
// https://vitejs.dev/config/
export default defineConfig({
plugins,
base: process.env.TAURI_ENV_PLATFORM ? "/" : "./",
clearScreen: false,
server: {
headers: {
"Cross-Origin-Embedder-Policy": "require-corp",
"Cross-Origin-Opener-Policy": "same-origin",
},
strictPort: true,
},
envPrefix: ["VITE_", "TAURI_", "AMLL_", "SENTRY_"],
build: {
// Tauri uses Chromium on Windows and WebKit on macOS and Linux
target:
process.env.TAURI_ENV_PLATFORM === "windows" ? "chrome105" : "safari15",
// don't minify for debug builds
minify: !process.env.TAURI_ENV_DEBUG ? "esbuild" : false,
// produce sourcemaps for debug builds
sourcemap: true,
},
resolve: {
alias: Object.assign(
{
$: resolve(__dirname, "src"),
},
AMLL_LOCAL_EXISTS
? {
// for development, use the local copy of the AMLL library
"@applemusic-like-lyrics/core": resolve(
__dirname,
"../applemusic-like-lyrics/packages/core/src",
),
"@applemusic-like-lyrics/react": resolve(
__dirname,
"../applemusic-like-lyrics/packages/react/src",
),
}
: {},
) as Record<string, string>,
},
worker: {
format: "es",
},
});