-
Notifications
You must be signed in to change notification settings - Fork 6
/
rollup.config.mjs
65 lines (62 loc) · 2.03 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
62
63
64
65
import { swc, minify } from 'rollup-plugin-swc3'
/** @type {import('rollup').RollupOptions} */
const base = {
input: './src/Async-Call.ts',
output: outputMatrix('base'),
plugins: [swc({ sourceMaps: true })],
}
/** @type {import('rollup').RollupOptions} */
const full = {
input: './src/index.ts',
output: outputMatrix('full'),
plugins: [swc({ sourceMaps: true })],
}
export default [base, full]
/**
* @param {string} name
* @param {('es' | 'umd')[]} format
* @returns {import('rollup').OutputOptions[]}
*/
function outputMatrix(name, format = ['es', 'umd']) {
return format.flatMap((f) => {
/** @returns {import('rollup').OutputOptions} */
const base = (compress = false) => {
const baseName = getBaseName(name, compress)
return {
file: `./out/${baseName}.${f === 'es' ? 'm' : ''}js`,
name: 'AsyncCall',
sourcemap: true,
format: f,
banner: `/// <reference types="./${baseName}.d.ts" />`,
plugins: [
compress &&
minify({
sourceMap: true,
compress: {
unsafe: true,
ecma: 2018,
// unsafe_arrows: true,
unsafe_symbols: true,
unsafe_undefined: true,
drop_debugger: false,
pure_getters: true,
keep_fargs: false,
module: f === 'es',
},
ecma: 2018,
module: f === 'es',
}),
],
}
}
return [base(false), base(true)]
})
}
/**
* @param {string} name
* @param {boolean} compress
*/
function getBaseName(name, compress) {
if (!compress) return name
return `${name}.min`
}