-
Notifications
You must be signed in to change notification settings - Fork 5
/
rollup.config.js
75 lines (58 loc) · 2.19 KB
/
rollup.config.js
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
import rpi_jsy from 'rollup-plugin-jsy'
import rpi_dgnotify from 'rollup-plugin-dgnotify'
import rpi_resolve from '@rollup/plugin-node-resolve'
import rpi_terser from '@rollup/plugin-terser'
import rpi_virtual from '@rollup/plugin-virtual'
import pkg from './package.json' with {type: 'json'}
const _rpis_ = (tag, defines, ...args) => [
rpi_virtual({
'code/version.js': `export const version = '${pkg.version}${tag || ''}'`,
}),
rpi_jsy({defines}),
rpi_resolve(),
...args,
rpi_dgnotify()]
const _cfg_ = {
external: id => /^\w*:/.test(id),
plugins: _rpis_(null, {}) }
const cfg_core = { ..._cfg_,
plugins: _rpis_(null, {}) }
const cfg_nodejs = { ..._cfg_,
plugins: _rpis_('-node', {PLAT_NODEJS: true}) }
const cfg_deno = { ..._cfg_,
plugins: _rpis_('-deno', {PLAT_DENO: true}) }
const cfg_web = { ..._cfg_,
plugins: _rpis_('-web', {PLAT_WEB: true}) }
let is_watch = process.argv.includes('--watch')
const cfg_web_min = is_watch ? null : { ... cfg_web,
plugins: _rpis_('-web', {PLAT_WEB: true}, rpi_terser()) }
export default [
... add_entrypoint('index'),
... add_entrypoint('v4'),
... add_entrypoint('v5'),
... add_entrypoint('full-v4'),
... add_entrypoint('full-v5'),
... add_entrypoint('basic-v4'),
... add_entrypoint('basic-v5'),
]
function * add_entrypoint(src_name, opt={}) {
const input = `code/${src_name}.js`
if (cfg_core)
yield ({ ... cfg_core, input,
output: { file: `esm/${src_name}.js`, format: 'es', sourcemap: true } })
if (cfg_nodejs)
yield ({ ... cfg_nodejs, input, output: [
{ file: `cjs/${src_name}.cjs`, format: 'cjs', exports:opt.exports || 'named', sourcemap: true },
{ file: `esm/node/${src_name}.js`, format: 'es', sourcemap: true },
{ file: `esm/node/${src_name}.mjs`, format: 'es', sourcemap: true },
]})
if (cfg_deno)
yield ({ ... cfg_deno, input,
output: { file: `esm/deno/${src_name}.js`, format: 'es', sourcemap: true } })
if (cfg_web)
yield ({ ... cfg_web, input,
output: { file: `esm/web/${src_name}.js`, format: 'es', sourcemap: true } })
if (cfg_web_min)
yield ({ ... cfg_web_min, input,
output: { file: `esm/web/${src_name}.min.js`, format: 'es', sourcemap: false } })
}