-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathrollup.config.js
63 lines (54 loc) · 1.41 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
import { readdirSync } from 'node:fs'
import path from 'node:path'
import terser from '@rollup/plugin-terser'
const files = readdirSync('./src', { recursive: true }).filter(f => ['.js', '.mjs'].includes(path.extname(f)))
const excludeUmdFor = /server\/?/
const extConfig = {
'.mjs': {
format: 'esm',
compact: true,
sourcemap: true,
},
'.cjs': {
format: 'cjs',
sourcemap: true,
compact: true,
strict: false,
},
'.js': {
format: 'umd',
name: 'tween',
file: 'dist/umd'
}
}
const minConfig = {
plugins: [terser()]
}
const getFileConfig = (file) => {
const { dir, name } = path.parse(file)
const distPath = `dist/${dir}/${name}`
return {
input: `src/${file}`,
output: Object.keys(extConfig)
.filter(ext => extConfig[ext].format != 'umd' || (extConfig[ext].format == 'umd' && !excludeUmdFor.test(file)))
.map(ext => [
{
...extConfig[ext],
file: extConfig[ext].format == 'umd'
? `${extConfig[ext].file}/${dir}/${name}${ext}`
: distPath + ext,
},
{
...extConfig[ext],
file: extConfig[ext].format == 'umd'
? `${extConfig[ext].file}/${dir}/${name}.min${ext}`
: `${distPath}.min${ext}`,
...minConfig,
}
]).flat()
}
}
const getRollupConfig = () => {
return files.map(file => getFileConfig(file))
}
export default getRollupConfig()