forked from fullcalendar/fullcalendar-react
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathrollup.config.js
68 lines (63 loc) · 1.82 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
import nodeResolve from '@rollup/plugin-node-resolve'
import commonjs from '@rollup/plugin-commonjs'
import babel from '@rollup/plugin-babel'
import replace from '@rollup/plugin-replace'
import postcss from 'rollup-plugin-postcss'
import sourcemaps from 'rollup-plugin-sourcemaps'
import pkgJson from './package.json'
export default [
// CJS
{
input: './dist/index.js', // the esm file
output: {
file: './dist/index.cjs',
format: 'cjs',
exports: 'named',
},
external: buildDepRegexps(),
},
// Tests
{
input: './tests/index.jsx',
output: {
format: 'iife',
file: './tests/dist/index.js',
sourcemap: 'inline',
},
plugins: [
sourcemaps(), // read sourcemaps from input files
replace({ // important it goes first
preventAssignment: true,
values: {
'process.env.NODE_ENV': '"development"' // needed for @testing-library/react
}
}),
nodeResolve({
browser: true // needed for @testing-library/react
}),
commonjs(), // for importing commonjs modules
babel({ // will automatically use babel.config.cjs
babelHelpers: 'bundled',
inputSourceMap: false, // only way sourcemaps plugin will work
}),
postcss({
config: false // don't look in current and parent dirs for a config
})
]
},
]
// ensures subpaths of packages are matched
function buildDepRegexps() {
const pkgNames = Object.keys({
...pkgJson.dependencies,
...pkgJson.peerDependencies,
...pkgJson.optionalDependencies,
})
return pkgNames.map((pkgName) => {
return RegExp(`^${escapeRegExp(pkgName)}($|/)`)
})
}
// https://stackoverflow.com/a/6969486/96342
function escapeRegExp(string) {
return string.replace(/[.*+?^${}()|[\]\\]/g, '\\$&'); // $& means the whole matched string
}