-
Notifications
You must be signed in to change notification settings - Fork 0
/
vite.config.ts
70 lines (68 loc) · 1.63 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
import { defineConfig } from 'vite';
import vue from '@vitejs/plugin-vue';
import cdn from 'vite-plugin-cdn2';
import { Mode, plugin as markdown } from 'vite-plugin-markdown';
declare const process: {
env: {
GITHUB_PAGES?: string;
VITE_GIT_COMMIT_HASH?: string;
};
};
export default defineConfig({
plugins: [
vue(),
cdn({
modules: [
{
name: '@techstark/opencv-js',
relativeModule: 'dist/opencv.js',
global: 'cv',
},
],
resolve: {
name: '@techstark/opencv-js',
setup() {
return {
url: 'https://cdn.jsdmirror.cn/npm/@techstark/opencv-js@4.10.0-release.1/dist/opencv.js',
injectTo: 'body',
attrs: {
async: true,
onload:
"cv.onRuntimeInitialized = () => { document.dispatchEvent(new Event('opencv-loaded')); }",
},
};
},
},
}),
markdown({ mode: [Mode.HTML] }),
],
server: {
// hmr: false,
headers: {
'Cross-Origin-Opener-Policy': 'same-origin',
'Cross-Origin-Embedder-Policy': 'require-corp',
},
},
build: {
commonjsOptions: {
transformMixedEsModules: true,
},
},
resolve: {
alias: {
pikafish: 'third_party/pikafish.js',
'@': './src',
},
},
optimizeDeps: {
include: ['pikafish'],
},
// 根据环境动态设置 base
base: process.env.GITHUB_PAGES === 'true' ? '/xiangqi-analysis/' : '/',
define: {
'import.meta.env.VITE_GIT_COMMIT_HASH': JSON.stringify(
process.env.VITE_GIT_COMMIT_HASH
),
},
assetsInclude: ['**/*.woff2'],
});