-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathvite.config.ts
More file actions
82 lines (75 loc) · 2.59 KB
/
vite.config.ts
File metadata and controls
82 lines (75 loc) · 2.59 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
import { defineConfig } from 'vite';
import monkey from 'vite-plugin-monkey';
import path from 'path';
import fs from 'fs';
// Get the script name from environment variable
const scriptName = process.env.VITE_SCRIPT || 'playground';
const packageJson = JSON.parse(fs.readFileSync('./package.json', 'utf-8'));
const scripts: Record<string, { name: string; match: string[]; entry: string }> = {
'playground': {
name: 'LessWrong GraphQL Helper',
match: ['https://www.lesswrong.com/*', 'https://forum.effectivealtruism.org/*'],
entry: 'src/scripts/playground/main.ts',
},
'power-reader': {
name: 'LW Power Reader',
match: [
'https://www.lesswrong.com/*',
'https://forum.effectivealtruism.org/*',
'https://aistudio.google.com/*',
'https://arena.ai/*',
'https://www.arena.ai/*'
],
entry: 'src/scripts/power-reader/main.ts',
}
};
const config = scripts[scriptName];
if (!config) {
throw new Error(`Unknown script: ${scriptName}`);
}
export default defineConfig({
server: {
cors: true,
headers: {
'Access-Control-Allow-Private-Network': 'true',
},
},
plugins: [
monkey({
entry: path.resolve(__dirname, config.entry),
userscript: {
name: config.name,
namespace: 'npm/vite-plugin-monkey',
match: config.match,
author: 'Wei Dai',
grant: [
'GM_addStyle',
'GM_xmlhttpRequest',
'GM_setValue',
'GM_getValue',
'GM_log',
'GM_deleteValue',
'GM_addValueChangeListener',
'GM_removeValueChangeListener',
'GM_openInTab',
],
connect: ['lesswrong.com', 'forum.effectivealtruism.org', 'arena.ai', 'firestore.googleapis.com'],
'run-at': 'document-start',
},
build: {
fileName: `${scriptName}.user.js`,
}
}),
],
resolve: {
alias: {
'@shared': path.resolve(__dirname, 'src/shared'),
},
},
define: {
'__APP_VERSION__': JSON.stringify(packageJson.version),
'__PR_FIRESTORE_PROJECT_ID__': JSON.stringify(process.env.PR_FIRESTORE_PROJECT_ID || ''),
'__PR_FIRESTORE_API_KEY__': JSON.stringify(process.env.PR_FIRESTORE_API_KEY || ''),
'__PR_FIRESTORE_HOST__': JSON.stringify(process.env.PR_FIRESTORE_HOST || ''),
},
});