-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathrollup.config.js
More file actions
executable file
·89 lines (80 loc) · 2.08 KB
/
rollup.config.js
File metadata and controls
executable file
·89 lines (80 loc) · 2.08 KB
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
import fs from 'fs'
import babel from '@rollup/plugin-babel'
import json from '@rollup/plugin-json'
import resolve from '@rollup/plugin-node-resolve'
import terser from '@rollup/plugin-terser'
import cleanup from 'rollup-plugin-cleanup'
const pkg = process.env.PACKAGE
const env = process.env.NODE_ENV ?? 'development'
// The config assumes rollup -c is invoked from a package/${pkg} directory
// The build commands assume they are executed from the root directory
process.chdir('../../')
const extensions = ['.js', '.jsx', '.es6', '.es', '.mjs', '.ts', '.tsx']
const babelConfig = {
extensions,
exclude: /node_modules/,
babelHelpers: 'bundled',
comments: false,
plugins: [],
}
let input = './packages/' + pkg + '/src/index.tsx'
if (!fs.existsSync(input)) {
input = input.replace('.tsx', '.ts')
}
const commonPlugins = [
resolve({
module: true,
jsnext: true,
main: true,
browser: true,
extensions,
modulesOnly: true,
}),
json(),
babel(babelConfig),
terser({ mangle: { keep_fnames: env === 'development' } }),
cleanup(),
]
// ignore warning about circular dependencies in d3-interpolate
const D3_WARNING = /Circular dependency.*d3-interpolate/
const commonConfig = {
input,
external: [
'react',
'react-dom',
'react/jsx-runtime',
'framer-motion',
'd3-scale',
'd3-shape',
'd3-scale-chromatic',
'd3-interpolate',
'lodash',
],
plugins: commonPlugins,
onwarn: function (message) {
if (D3_WARNING.test(message)) {
return
}
},
}
const configs = [
{
...commonConfig,
output: {
file: `./packages/${pkg}/dist/chsk-${pkg}.es.js`,
format: 'es',
name: `@chsk/${pkg}`,
sourcemap: true,
},
},
{
...commonConfig,
output: {
file: `./packages/${pkg}/dist/chsk-${pkg}.umd.js`,
format: 'umd',
name: `@chsk/${pkg}`,
sourcemap: true,
},
},
]
export default configs