-
Notifications
You must be signed in to change notification settings - Fork 9
/
rollup.config.mjs
61 lines (57 loc) · 1.65 KB
/
rollup.config.mjs
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
import nodeResolve from "@rollup/plugin-node-resolve";
import typescript from "@rollup/plugin-typescript";
import { dirname, join, parse, resolve } from "node:path";
import url from "node:url";
const isWatching = !!process.env.ROLLUP_WATCH;
const banner = `/**!
* @author Elgato
* @module elgato/streamdeck
* @license MIT
* @copyright Copyright (c) Corsair Memory Inc.
*/`;
/**
* Defines a rollup configuration for the specified input and output.
* @param {string} input Path to the input TypeScript file, with "src/" omitted.
* @param {string} output Path to the desired output JavaScript file, with "dist/" omitted.
* @returns Rollup configuration.
*/
function defineConfig(input, output) {
return {
input: join("src", input),
output: {
banner,
file: join("dist", output),
sourcemap: isWatching,
sourcemapPathTransform: (relativeSourcePath, sourcemapPath) => {
return url.pathToFileURL(resolve(dirname(sourcemapPath), relativeSourcePath)).href;
},
},
external: ["ws", "@elgato/schemas/streamdeck/plugins"],
plugins: [
typescript({
tsconfig: join("src", dirname(input), "tsconfig.build.json"),
mapRoot: isWatching ? "./" : undefined,
}),
nodeResolve(),
{
name: "emit-dts",
generateBundle() {
const types = `"../types/${dirname(input)}"`;
this.emitFile({
fileName: `${parse(output).name}.d.ts`,
type: "asset",
source: `${banner}
import streamDeck from ${types};
export * from ${types};
export default streamDeck;
`,
});
},
},
],
};
}
/**
* Rollup configuration.
*/
export default [defineConfig("plugin/index.ts", "index.js"), defineConfig("ui/index.ts", "browser.js")];