-
Notifications
You must be signed in to change notification settings - Fork 0
/
vite.config.ts
76 lines (75 loc) · 2.35 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
import typescript from 'rollup-plugin-typescript2';
import { defineConfig } from 'vite';
import monkey from 'vite-plugin-monkey';
import sites from './src/sites/data';
export default defineConfig({
build: {
target: 'es2020',
},
plugins: [
{
enforce: 'pre',
...typescript(),
},
monkey({
entry: 'src/main.ts',
build: {
metaFileName: true,
},
userscript: {
icon: 'https://cdn.jsdelivr.net/gh/microsoft/fluentui-emoji/assets/Musical%20score/3D/musical_score_3d.png',
description: {
'zh-CN': '适用于Gazelle等架构站点的音乐转种工具',
},
namespace: 'https://dvxg.de/',
match: [
'https://logs.musichoarders.xyz/',
...Object.entries(sites).flatMap(([_fw, framework]) =>
Object.entries(framework).flatMap(([_st, site]) =>
Object.entries(site.include).flatMap(([_cat, path]) =>
typeof path === 'string'
? `${new URL(path, `https://*.${site.hostname}`)}*`
: path.map(
(p) => `${new URL(p, `https://*.${site.hostname}`)}*`,
),
),
),
),
],
resource: {
brotli_wasm_bg:
'https://cdn.jsdelivr.net/npm/brotli-wasm@3/pkg.web/brotli_wasm_bg.wasm',
},
updateURL:
'https://github.com/davidxuang/ostrich/releases/latest/download/ostrich.meta.js',
downloadURL:
'https://github.com/davidxuang/ostrich/releases/latest/download/ostrich.user.js',
},
}),
(() => {
const reExt = /\.(?:js|cjs|mjs)$/;
const reBlk = /^[ \t]*\/\*(.*\n)*?[ \t]*\*\/[ \t]*\n/gm;
return {
name: 'hack',
enforce: 'post',
// strip brotli-wasm comments
transform(code, id, _options) {
return {
code: id.match(reExt) ? code.replace(reBlk, '') : code,
};
},
// magic __import__
generateBundle(_options, bundle, _isWrite) {
Object.entries(bundle).forEach(([f, file]) => {
if (
typeof file['code'] === 'string' &&
file.fileName.endsWith('.user.js')
) {
file['code'] = file['code'].replace('__import__', 'import');
}
});
},
};
})(),
],
});