-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathvite.config.ts
More file actions
62 lines (57 loc) · 2.04 KB
/
Copy pathvite.config.ts
File metadata and controls
62 lines (57 loc) · 2.04 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
import { defineConfig, Plugin } from 'vite';
import react from '@vitejs/plugin-react';
const ENTRY = 'src/renderer/src/main.tsx';
// Tampermonkey/Violentmonkey metadata block. @match is intentionally broad — main.tsx itself
// verifies it is running on a real Jellyfin page (#reactRoot + window.ApiClient) before it
// injects anything, so a wide @match here just means "try on every page", not "run on every page".
const USERSCRIPT_HEADER = `// ==UserScript==
// @name Jellyforge AnvilCSS
// @namespace https://github.com/Jellyforge-Dev/AnvilCSS
// @version 1.0.0
// @description Floating, live CSS theme builder sidebar for Jellyfin — edit colors, background, logos, typography and components and see them applied to your real Jellyfin instance instantly.
// @author Jellyforge
// @match *://*/*
// @grant none
// @run-at document-idle
// @noframes
// ==/UserScript==
`;
// `rollupOptions.output.banner` is silently dropped by Vite's lib-mode output resolution for
// single-format iife builds — prepending it in generateBundle is the reliable path instead.
function userscriptBanner(banner: string): Plugin {
return {
name: 'userscript-banner',
generateBundle(_options, bundle) {
for (const file of Object.values(bundle)) {
if (file.type === 'chunk') {
file.code = banner + file.code;
}
}
}
};
}
export default defineConfig(({ command }) => ({
plugins: [react(), ...(command === 'build' ? [userscriptBanner(USERSCRIPT_HEADER)] : [])],
publicDir: false,
build:
command === 'build'
? {
outDir: 'dist',
emptyOutDir: true,
assetsInlineLimit: Infinity,
cssCodeSplit: false,
minify: 'esbuild',
lib: {
entry: ENTRY,
name: 'AnvilCSSInjector',
formats: ['iife'],
fileName: () => 'anvil-customizer.user.js'
},
rollupOptions: {
output: {
inlineDynamicImports: true
}
}
}
: undefined
}));