/
rollup.config.js
119 lines (108 loc) · 2.98 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
import fs from 'fs'
import { camelCase, upperFirst } from 'lodash'
import babel from '@rollup/plugin-babel'
import resolve from '@rollup/plugin-node-resolve'
import stripBanner from 'rollup-plugin-strip-banner'
import cleanup from 'rollup-plugin-cleanup'
import size from 'rollup-plugin-size'
import visualizer from 'rollup-plugin-visualizer'
import { terser } from "rollup-plugin-terser"
const pkg = process.env.PACKAGE
const isWatching = process.env.ROLLUP_WATCH === 'TRUE'
const extensions = ['.js', '.jsx', '.es6', '.es', '.mjs', '.ts', '.tsx']
const babelConfig = {
extensions,
exclude: /node_modules/,
babelHelpers: 'bundled',
comments: false,
plugins: ['lodash'],
}
const externals = [
'prop-types',
'joi',
]
const mapGlobal = name => {
if (name.indexOf('@nivo') === 0) return 'nivo'
if (name.indexOf('d3-') === 0) return 'd3'
if (name.indexOf('recompose') === 0) return upperFirst(camelCase(name))
if (name === 'react') return 'React'
if (name === 'prop-types') return 'PropTypes'
if (name === 'react-motion') return 'ReactMotion'
return name
}
let input = `./packages/${pkg}/src/index.js`
// detect TS entry index file
if (fs.existsSync(`./packages/${pkg}/src/index.ts`)) {
input = `./packages/${pkg}/src/index.ts`
}
const common = {
input,
external: id => externals.includes(id)
|| id.indexOf('react') === 0
|| id.indexOf('d3') === 0
|| id.indexOf('@nivo') === 0
|| id.indexOf('lodash') === 0
|| id.indexOf('@react-spring') === 0,
}
const commonPlugins = [
stripBanner({
include: `./packages/${pkg}/src/**/*.js`,
}),
resolve({
module: true,
jsnext: true,
main: true,
browser: true,
extensions,
modulesOnly: true,
}),
babel(babelConfig),
!isWatching && terser(),
cleanup()
]
const configs = [
{
...common,
output: {
file: `./packages/${pkg}/dist/nivo-${pkg}.es.js`,
format: 'es',
name: `@nivo/${pkg}`,
sourcemap: true,
},
plugins: [
...commonPlugins,
!isWatching && size({
filename: `stats/${pkg}-size.es.json`,
}),
!isWatching && visualizer({
filename: `stats/${pkg}-stats.es.json`,
json: true,
})
].filter(Boolean),
}
]
if (!isWatching) {
configs.push({
...common,
output: {
file: `./packages/${pkg}/dist/nivo-${pkg}.cjs.js`,
format: 'cjs',
name: `@nivo/${pkg}`,
sourcemap: true,
},
plugins: commonPlugins,
})
configs.push({
...common,
output: {
file: `./packages/${pkg}/dist/nivo-${pkg}.umd.js`,
format: 'umd',
extend: true,
name: 'nivo',
globals: mapGlobal,
sourcemap: true,
},
plugins: commonPlugins,
})
}
export default configs