forked from ealmansi/set-interval-async
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathrollup.config.js
145 lines (141 loc) · 3.51 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
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
import babel from '@rollup/plugin-babel'
import nodePolyfills from 'rollup-plugin-node-polyfills'
import commonJS from '@rollup/plugin-commonjs'
import fs from 'fs'
import globals from 'rollup-plugin-node-globals'
import minify from 'rollup-plugin-babel-minify'
import path from 'path'
import pkg from './package.json'
import resolve from '@rollup/plugin-node-resolve'
export default [
{
input: path.resolve(__dirname, 'src', 'index.js'),
output: {
cjs: {
file: pkg.main
},
es: {
file: pkg.module
},
iife: {
file: pkg.unpkg,
name: pkg.library
}
}
},
...['dynamic', 'fixed', 'legacy'].map((curr) => {
return {
input: path.resolve(__dirname, 'src', `${curr}.js`),
output: {
cjs: {
file: path.resolve(__dirname, curr, 'index.js')
},
es: {
file: path.resolve(__dirname, curr, 'index.mjs')
}
}
}
})
].reduce(
(acc, curr) => {
return acc.concat(
[
{
input: curr.input,
external: isExternal,
output: [
{
file: curr.output.cjs.file,
format: 'cjs',
sourcemap: true
},
{
file: curr.output.es.file,
format: 'es',
sourcemap: true
}
],
plugins: [
babel({
presets: [
[
'@babel/preset-env',
{
modules: false,
targets: {
node: '6'
}
}
]
],
babelHelpers: 'runtime',
plugins: ['@babel/plugin-transform-runtime']
})
],
onwarn: onWarning
},
...(curr.output.iife !== undefined ? [{
input: curr.input,
output: [
{
file: curr.output.iife.file,
format: 'iife',
name: curr.output.iife.name,
sourcemap: true
}
],
context: 'window',
plugins: [
globals(),
nodePolyfills(),
resolve({
browser: true,
preferBuiltins: true
}),
commonJS(),
babel({
exclude: ['node_modules/**'],
presets: [
[
'@babel/preset-env',
{
modules: false,
targets: {
browsers: ['> 0.25%, not dead']
}
}
]
],
babelHelpers: 'runtime',
plugins: ['@babel/plugin-transform-runtime']
}),
minify({
comments: false,
banner: getBanner(),
bannerNewLine: false,
sourceMap: true
})
],
onwarn: onWarning
}] : [])
]
)
},
[]
)
function isExternal (candidate) {
return Object.keys(pkg.dependencies).some(dependency => {
return candidate.startsWith(dependency)
})
}
function getBanner () {
const filePath = path.resolve(__dirname, 'src', 'banner.js')
return fs.readFileSync(filePath).toString().trim()
}
function onWarning (warning, warn) {
// https://github.com/Comandeer/rollup-plugin-babel-minify/issues/145
if (warning.message.includes('transformBundle hook')) {
return
}
warn(warning)
}