-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathvite.config.js
88 lines (79 loc) · 2.08 KB
/
vite.config.js
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
import vue2 from "@vitejs/plugin-vue2";
import chalk from "chalk";
import fs from "fs";
import { fileURLToPath } from "url";
import { defineConfig } from "vite";
import banner from "vite-plugin-banner";
import cssInjectedByJsPlugin from "vite-plugin-css-injected-by-js";
import { createBanner } from "./userscript";
const buildNumberFile = fileURLToPath(new URL("./BUILD", import.meta.url));
// Write new build number to file.
function writeNewBuildNumber(number) {
fs.writeFile(buildNumberFile, String(number), function (err) {
if (!err) {
console.log(chalk.yellowBright(`build number set to ${number}`));
}
});
}
let buildNumber = 0;
// Read build number from local file.
if (fs.existsSync(buildNumberFile)) {
const data = fs.readFileSync(buildNumberFile, "UTF-8");
buildNumber = +data || 0;
}
export default defineConfig(({ mode }) => {
const isDev = mode === "dev";
return {
resolve: {
alias: {
"@": "/src",
},
},
build: {
minify: false,
cssMinify: true,
cssCodeSplit: false,
sourcemap: false,
assetsInlineLimit: Number.POSITIVE_INFINITY, // always inline assets
rollupOptions: {
input: {
[process.env.npm_package_name]: fileURLToPath(
new URL("./src/main.js", import.meta.url),
),
},
output: {
entryFileNames: "[name].user.js",
format: "iife",
globals: {
vue: "Vue",
xbytes: "xbytes",
},
},
external: ["vue", "xbytes", /^\/images/],
},
},
plugins: [
vue2(),
banner({
content: (fileName) => {
if (isDev) {
writeNewBuildNumber(++buildNumber);
}
return fileName.endsWith(".js")
? createBanner(isDev, buildNumber)
: "";
},
verify: false,
}),
cssInjectedByJsPlugin({
injectCode: (cssCode) => {
return `GM_addStyle(${cssCode})`;
},
}),
],
test: {
include: ["tests/*.{test,spec}.js"],
globals: true,
},
};
});