-
Notifications
You must be signed in to change notification settings - Fork 203
/
Copy pathrollup.config.ts
101 lines (92 loc) · 2.43 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
import resolve from './rollup.plugin.resolve';
import dts from 'rollup-plugin-dts';
import license from 'rollup-plugin-license';
import fs from 'fs';
import typescript from '@rollup/plugin-typescript';
import { ModuleFormat, RollupOptions } from 'rollup';
import esm from './rollup.config.esm';
import cjs from './rollup.config.cjs';
import webpack from './rollup.config.webpack';
import vite from './rollup.config.vite';
function getGitBranch(): string {
const filepath = '.git/HEAD';
if (!fs.existsSync(filepath)) {
throw new Error('.git/HEAD does not exist');
}
const buf = fs.readFileSync(filepath);
const match = /ref: refs\/heads\/([^\n]+)/.exec(buf.toString());
return match ? match[1] : '';
}
const commonOutput = {
name: 'alphaTab',
format: 'umd' as ModuleFormat,
globals: {
jQuery: 'jQuery'
}
};
const bundlePlugins = [
typescript({
tsconfig: './tsconfig.build.json',
outputToFilesystem: true
}),
license({
banner: {
content: {
file: 'LICENSE.header'
},
data() {
let buildNumber = process.env.GITHUB_RUN_NUMBER || 0;
let gitBranch = getGitBranch();
return {
branch: gitBranch,
build: buildNumber
};
}
}
}),
resolve({
mappings: {
'@src': 'dist/lib'
}
})
];
const isWatch = !!process.env.ROLLUP_WATCH;
export default [
...esm(isWatch, commonOutput, bundlePlugins),
...cjs(isWatch, commonOutput, bundlePlugins),
//
// typescript type declarations
{
input: 'dist/types/alphaTab.main.d.ts',
output: [
{
file: 'dist/alphaTab.d.ts',
format: 'es'
}
],
plugins: [
dts(),
resolve({
mappings: {
'@src': 'dist/types'
},
types: true
})
]
} satisfies RollupOptions,
//
// Bundlers
...webpack(isWatch, bundlePlugins),
...vite(isWatch, bundlePlugins)
].map(x => {
x.onLog = (level, log, handler) => {
if (log.code === 'CIRCULAR_DEPENDENCY') {
return; // Ignore circular dependency warnings
}
handler(level, log);
};
if (x.watch) {
x.watch.clearScreen = false;
}
return x;
});