-
Notifications
You must be signed in to change notification settings - Fork 8
/
Copy pathrollup.config.ts
51 lines (45 loc) · 1.33 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
import json from '@rollup/plugin-json'
import resolve from '@rollup/plugin-node-resolve'
import typescript from '@rollup/plugin-typescript'
import type { OutputOptions, RollupWatchOptions } from 'rollup'
import { watch } from 'rollup'
function getOptions(output: OutputOptions | OutputOptions[]) {
return {
input: 'src/index.ts',
output,
plugins: [
resolve({
browser: true,
}),
typescript(),
json({
compact: true,
}),
],
} as RollupWatchOptions
}
if (process.env.NODE_ENV === 'development') {
const watcher = watch(getOptions(getOutput('umd')))
console.log('rollup is watching for file change...')
watcher.on('event', (event) => {
switch (event.code) {
case 'START':
console.log('rollup is rebuilding...')
break
case 'ERROR':
console.log('error in rebuilding.')
break
case 'END':
console.log('rebuild done.\n\n')
}
})
}
const formats = ['es', 'umd']
function getOutput(format: 'es' | 'umd') {
return {
format,
file: `dist/render-engine.${format === 'es' ? 'mjs' : 'js'}`,
name: 'RenderEngine',
}
}
export default getOptions(formats.map(getOutput))