-
Notifications
You must be signed in to change notification settings - Fork 3
/
rollup.config.ts
76 lines (66 loc) · 2.35 KB
/
rollup.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 alias from "@rollup/plugin-alias";
import typescript from "@rollup/plugin-typescript";
import { resolve } from "path";
import externalResource, {
getResourceMapping,
} from "./scripts/external-resource";
const root = "src/app";
export default {
input: `${root}/index.ts`,
output: {
banner: () => {
// eslint-disable-next-line global-require
const meta = require("./package.json");
const scriptMeta = meta["user-script-meta"] || {};
scriptMeta.version = meta.version;
if (!scriptMeta.name && meta.name) scriptMeta.name = meta.name;
if (!scriptMeta.namespace && meta.homepage)
scriptMeta.namespace = meta.homepage;
if (!scriptMeta.description && meta.description)
scriptMeta.description = meta.description;
if (!scriptMeta.author && (meta.author?.name || meta.author))
scriptMeta.author = meta.author?.name || meta.author;
if (!scriptMeta.homepage && meta.homepage)
scriptMeta.homepage = meta.homepage;
if (!scriptMeta.supportURL && (meta.bugs?.url || meta.homepage))
scriptMeta.supportURL = meta.bugs.url || meta.homepage;
scriptMeta.resource = getResourceMapping({
baseUrl: scriptMeta.homepage,
});
const metaString = Object.entries(scriptMeta)
.map(([metaKey, metaValue]) => {
function getMetaString(key, value) {
return `// @${key.padEnd(15)} ${value}`;
}
if (Array.isArray(metaValue)) {
return metaValue.map(v => getMetaString(metaKey, v)).join("\n");
}
if (typeof metaValue === "object") {
return Object.entries(metaValue)
.map(([k, v]) => getMetaString(`${metaKey}:${k}`, v))
.join("\n");
}
return getMetaString(metaKey, metaValue);
})
.join("\n");
return `// ==UserScript==\n${metaString}\n// ==/UserScript==\n`;
},
file: "dist/bundle.user.js",
format: "umd",
minifyInternalExports: false,
},
plugins: [
alias({
entries: [
{ find: "@pages", replacement: resolve(__dirname, "dist/pages") },
{ find: "@common", replacement: resolve(__dirname, "src/common") },
],
}),
typescript({
tsconfig: `${root}/tsconfig.json`,
}),
externalResource({
production: process.env.NODE_ENV === "production",
}),
],
};