-
Notifications
You must be signed in to change notification settings - Fork 11
/
rollup.config.js
56 lines (53 loc) · 1.57 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
import babel from '@rollup/plugin-babel'
import peerDepsExternal from 'rollup-plugin-peer-deps-external'
import { nodeResolve } from '@rollup/plugin-node-resolve'
import commonjs from '@rollup/plugin-commonjs'
import json from '@rollup/plugin-json'
import replace from 'rollup-plugin-replace'
import postcss from 'rollup-plugin-postcss'
import pkg from './package.json'
/**
* Used for generating external dependencies
* Credit: Mateusz Burzyński (https://github.com/Andarist)
* Source: https://github.com/rollup/rollup-plugin-babel/issues/148#issuecomment-399696316
*/
const makeExternalPredicate = (externalArr) => {
if (externalArr.length === 0) {
return () => false;
}
const pattern = new RegExp(`^(${externalArr.join('|')})($|/)`);
return (id) => pattern.test(id);
};
export default commandLineArgs => ({
input: pkg.source,
output: [
{
file: pkg.main,
format: 'cjs',
sourcemap: true,
},
{
file: pkg.module,
format: 'esm',
sourcemap: true,
},
],
plugins: [
nodeResolve(),
peerDepsExternal(),
babel({ babelHelpers: 'bundled', exclude: 'node_modules/**' }),
commonjs(),
json(),
postcss({
extensions: ['.css']
}),
...(commandLineArgs.configDebug === true
? []
: [replace({ 'process.env.NODE_ENV': JSON.stringify('production') })]),
],
external: makeExternalPredicate([
// Handles both dependencies and peer dependencies so we don't have to manually maintain a list
...Object.keys(pkg.dependencies || {}),
...Object.keys(pkg.peerDependencies || {}),
]),
});