-
Notifications
You must be signed in to change notification settings - Fork 10
/
rollup.config.mjs
74 lines (67 loc) · 1.63 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
66
67
68
69
70
71
72
73
74
import resolve from '@rollup/plugin-node-resolve'
import terser from '@rollup/plugin-terser'
import { babel } from '@rollup/plugin-babel'
import { readFileSync } from 'fs'
const pkg = JSON.parse(readFileSync(new URL('package.json', import.meta.url)))
function globalName (name) {
const parts = name.split('-')
for (let i = 2; i < parts.length; i++) {
parts[i] = parts[i][0].toUpperCase() + parts[i].slice(1)
}
return parts.join('')
}
const config_umd_full = {
input: 'index.mjs',
output: [
{
file: `dist/${pkg.name}.js`,
format: 'umd',
name: globalName(pkg.name),
plugins: [
// Here terser is used only to force ascii output
terser({
mangle: false,
compress: false,
format: { comments: 'all', beautify: true, ascii_only: true, indent_level: 2 }
})
]
},
{
file: `dist/${pkg.name}.min.js`,
format: 'umd',
name: globalName(pkg.name),
plugins: [
terser({
format: { ascii_only: true }
})
]
}
],
plugins: [
resolve(),
babel({ babelHelpers: 'bundled' }),
{
banner () {
return `/*! ${pkg.name} ${pkg.version} https://github.com/${pkg.repository} @license ${pkg.license} */`
}
}
]
}
const config_cjs_no_deps = {
input: 'index.mjs',
output: {
file: 'dist/index.cjs.js',
format: 'cjs'
},
external: Object.keys(pkg.dependencies || {}),
plugins: [
resolve(),
babel({ babelHelpers: 'bundled' })
]
}
let config = [
config_umd_full,
config_cjs_no_deps
]
if (process.env.CJS_ONLY) config = [config_cjs_no_deps]
export default config