-
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathrollup.config.ts
109 lines (104 loc) · 3.03 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
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
import commonjs from "@rollup/plugin-commonjs";
import copy from "rollup-plugin-copy";
import nodeResolve from "@rollup/plugin-node-resolve";
import terser from "@rollup/plugin-terser";
import typescript from "@rollup/plugin-typescript";
import path from "node:path";
import url from "node:url";
import generatePi from "./rollup-plugin-gen-pi";
import { RollupOptions } from "rollup";
const isWatching = !!process.env.ROLLUP_WATCH || process.env.BUILD === "DEBUG";
const pluginId = "gg.dennis.firebot";
const sdPlugin = `${pluginId}.sdPlugin`;
const banner = `/**!
* @author Dennis Rijsdijk
* @module gg.dennis.firebot
* @license MIT
* @copyright Copyright (c) 2024 Dennis Rijsdijk
*/`;
/**
* @type {import('rollup').RollupOptions}
*/
const plugin: RollupOptions = {
input: "src/plugin/index.ts",
output: {
file: `${sdPlugin}/bin/plugin.js`,
banner,
sourcemap: isWatching,
sourcemapPathTransform: (relativeSourcePath, sourcemapPath) => {
return url.pathToFileURL(path.resolve(path.dirname(sourcemapPath), relativeSourcePath)).href;
}
},
plugins: [
{
name: "watch-externals",
buildStart: function () {
this.addWatchFile(`${sdPlugin}/manifest.json`);
}
},
typescript({
tsconfig: "src/plugin/tsconfig.json",
mapRoot: isWatching ? "./" : undefined
}),
nodeResolve({
browser: false,
exportConditions: ["node"],
preferBuiltins: true
}),
commonjs(),
!isWatching && terser(),
{
name: "emit-module-package-file",
generateBundle() {
this.emitFile({ fileName: "package.json", source: `{ "type": "module" }`, type: "asset" });
}
}
]
};
const pi: RollupOptions = {
input: "src/pi/index.ts",
output: {
file: `${sdPlugin}/bin/pi.js`,
banner,
format: 'iife',
sourcemap: isWatching,
sourcemapPathTransform: (relativeSourcePath, sourcemapPath) => {
return url.pathToFileURL(path.resolve(path.dirname(sourcemapPath), relativeSourcePath)).href;
}
},
plugins: [
generatePi({
base: "src/pi/template.html",
actionsDir: "src/pi/templates",
pluginId: pluginId,
titleRows: {
default: 2,
map: {
display: 5
}
}
}),
{
name: "watch-externals",
buildStart: function () {
this.addWatchFile(`${sdPlugin}/manifest.json`);
}
},
typescript({
tsconfig: "src/pi/tsconfig.json",
mapRoot: isWatching ? "./" : undefined
}),
nodeResolve({
browser: true
}),
commonjs(),
copy({
targets: [{ src: "src/pi/sdpi.css", dest: `${sdPlugin}/bin` }]
}),
!isWatching && terser()
]
};
export default [
plugin,
pi
];