-
Notifications
You must be signed in to change notification settings - Fork 0
/
rollup.config.js
78 lines (73 loc) · 2.01 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
76
77
78
import fs from 'fs'
import path from 'path'
import dts from 'rollup-plugin-dts'
import license from 'rollup-plugin-license'
import { uglify } from 'rollup-plugin-uglify'
import packageConf from './package.json'
import baseConf from './rollup.config.base'
const isWatch = process.env.BUILD_ENV === 'watch'
const isDts = process.env.BUILD_ENV === 'dts'
const formats = ['es', 'umd']
function getEntries() {
const reg = /\.ts$/
return fs
.readdirSync(path.resolve(__dirname, './src'))
.filter(
filename =>
reg.test(filename) &&
!fs.statSync(path.resolve(__dirname, './src', filename)).isDirectory(),
)
.map(filename => ({
name: filename.replace(reg, ''),
filename: path.resolve(__dirname, './src', filename),
formats: formats.filter(f => f !== 'es'),
}))
}
const conf = entry => ({
input: entry.filename,
output: entry.formats.map(format => ({
file: `./lib/${format}/${entry.name}.js`,
format,
name: entry.name === 'index' ? 'MouseEvents' : `${entry.name}MouseEvents`,
})),
external: entry.external ? Object.keys(packageConf.dependencies || {}) : [],
plugins: [
...baseConf.plugins,
entry.needUglify !== false && uglify(),
license({
banner: `Bundle of <%= pkg.name %>
Generated: <%= moment().format('YYYY-MM-DD') %>
Version: <%= pkg.version %>
License: <%= pkg.license %>
Author: <%= pkg.author %>`,
}),
],
})
// eslint-disable-next-line no-nested-ternary
export default isWatch
? [
{
name: 'index',
filename: './src/index.ts',
formats: ['umd'],
needUglify: false,
},
].map(conf)
: isDts
? [
{
input: './src/index.ts',
output: [{ file: './index.d.ts', format: 'es' }],
plugins: [dts()],
},
]
: [
{
name: 'index',
filename: './src/index.ts',
formats: ['es'],
needUglify: false,
external: true,
},
...getEntries(),
].map(conf)