forked from CoderLine/alphaTab
-
Notifications
You must be signed in to change notification settings - Fork 0
/
rollup.config.esm.ts
116 lines (110 loc) · 4.47 KB
/
rollup.config.esm.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
110
111
112
113
114
115
116
import terser from '@rollup/plugin-terser';
import copy from 'rollup-plugin-copy'
import server from './rollup.plugin.server'
import MagicString from 'magic-string';
import { OutputOptions, Plugin, RollupOptions } from 'rollup';
/**
* Creates the ESM flavor configurations for alphaTab
*/
export default function esm(isWatch: boolean, commonOutput: Partial<OutputOptions>, bundlePlugins: Plugin[]): RollupOptions[] {
return [
// Core Bundle
{
input: `src/alphaTab.core.ts`,
output: [
{
file: 'dist/alphaTab.core.mjs',
format: 'es',
sourcemap: true
},
!isWatch && {
file: 'dist/alphaTab.core.min.mjs',
format: 'es',
plugins: [terser()],
sourcemap: true
}
].filter(e => typeof e == "object").map(o => ({ ...commonOutput, ...o } as OutputOptions)),
external: [],
watch: {
include: ['src/**'],
exclude: 'node_modules/**'
},
plugins: [
...bundlePlugins,
copy({
targets: [
{ src: 'font/bravura/*', dest: 'dist/font' },
{ src: 'font/sonivox/*', dest: 'dist/soundfont' }
]
}),
isWatch && server({
openPage: '/playground/control.html',
port: 8080
})
]
},
// Entry points
...[
{ input: "alphaTab.main", output: "alphaTab" },
{ input: "alphaTab.worker", output: "alphaTab.worker" },
{ input: "alphaTab.worklet", output: "alphaTab.worklet" }
].map(x => {
return {
input: `src/${x.input}.ts`,
output: [
{
file: `dist/${x.output}.mjs`,
format: 'es',
sourcemap: true,
plugins: [
{
name: 'adjust-script-paths',
renderChunk(code) {
const modifiedCode = new MagicString(code);
modifiedCode.replaceAll('alphaTab.core\'', 'alphaTab.core.mjs\'')
.replaceAll('alphaTab.worker\'', 'alphaTab.worker.mjs\'')
.replaceAll('alphaTab.worklet\'', 'alphaTab.worklet.mjs\'')
return {
code: modifiedCode.toString(),
map: modifiedCode.generateMap()
}
}
} as Plugin
],
},
{
file: `dist/${x.output}.min.mjs`,
format: 'es',
plugins: [
{
name: 'adjust-script-paths',
renderChunk(code) {
const modifiedCode = new MagicString(code);
modifiedCode.replaceAll('alphaTab.core\'', 'alphaTab.core.min.mjs\'')
.replaceAll('alphaTab.worker\'', 'alphaTab.worker.min.mjs\'')
.replaceAll('alphaTab.worklet\'', 'alphaTab.worklet.min.mjs\'')
return {
code: modifiedCode.toString(),
map: modifiedCode.generateMap()
}
}
} as Plugin,
terser()
],
sourcemap: true
}
],
external: [
'./alphaTab.core'
],
watch: {
include: [`src/${x.input}.ts`],
exclude: 'node_modules/**'
},
plugins: [
...bundlePlugins.filter(p => p.name !== 'resolve-typescript-paths'),
]
} as OutputOptions
}),
]
}