-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathvite.config.ts
96 lines (90 loc) · 2.33 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
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
import { resolve } from "node:path";
import { PluginOption } from "vite";
import { defineConfig } from "vitest/config";
import solidPlugin from "vite-plugin-solid";
const tampermonkey = () => {
const headers = `
// ==UserScript==
// @name Floating Luogu
// @namespace http://tampermonkey.net/
// @icon https://cdn.luogu.com.cn/upload/usericon/3.png
// @author yurzhang & tiger2005
// @homepage https://github.com/Nikaidou-Shinku/floating-luogu
// @description A plugin to decorate Luogu with exquisite user card.
// @include https://www.luogu.com.cn/*
// @version 0.4.0
// @grant GM_addStyle
// @license MIT
// ==/UserScript==
`.trim();
return {
name: "tampermonkey",
apply: "build",
enforce: "post",
generateBundle: (_options, bundle) => {
const cssBundle = bundle["style.css"];
if (!cssBundle || cssBundle.type !== "asset") {
return;
}
const css = cssBundle.source.toString().trim();
const [, target] = Object.entries(bundle)
.find(([name]) => name.includes("user.js")) ?? [];
if (!target || target.type !== "chunk") {
return;
}
target.code = `${headers}\n\nGM_addStyle(\`${css}\`);\n${target.code}`;
},
} as PluginOption;
};
export default defineConfig({
plugins: [
solidPlugin(),
tampermonkey(),
],
resolve: {
alias: {
"~": resolve(__dirname, "src"),
},
},
build: {
target: "esnext",
lib: {
entry: resolve(__dirname, "src/main.tsx"),
name: "userscript",
formats: ["iife"],
fileName: (format) => `flg.${format}.user.js`,
},
rollupOptions: {
output: {
inlineDynamicImports: true,
},
},
},
define: {
"process.env.NODE_ENV": "\"production\"",
},
css: {
modules: {
localsConvention: "camelCaseOnly",
},
},
test: {
environment: "jsdom",
transformMode: {
web: [/\.[jt]sx?$/],
},
coverage: {
all: true,
exclude: [
"coverage/**",
"dist/**",
"test{,s}/**",
"test{,-*}.{js,cjs,mjs,ts,tsx,jsx}",
"**/*{.,-}test.{js,cjs,mjs,ts,tsx,jsx}",
"**/{karma,rollup,webpack,vite,vitest,jest,ava,babel,nyc,cypress,tsup,build}.config.*",
"**/.{eslint,mocha,prettier}rc.{js,cjs,yml}",
"src/data/types.ts",
],
},
},
});