-
Notifications
You must be signed in to change notification settings - Fork 32
/
Copy pathrollup.config.js
54 lines (49 loc) · 1.34 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
import babel from "rollup-plugin-babel";
import { uglify } from "rollup-plugin-uglify";
import replace from "rollup-plugin-replace";
import filesize from "rollup-plugin-filesize";
import pkg from "./package.json";
const makeExternalPredicate = externalArr => {
if (externalArr.length === 0) {
return () => false;
}
const pattern = new RegExp(`^(${externalArr.join("|")})($|/)`);
return id => pattern.test(id);
};
const ensureArray = maybeArr =>
Array.isArray(maybeArr) ? maybeArr : [maybeArr];
const createConfig = ({ output, min = false, env } = {}) => ({
input: "src/index.js",
output: ensureArray(output).map(format =>
Object.assign({}, format, {
name: "ReactColorExtractor",
exports: "named",
globals: {
react: "React"
}
})
),
external: makeExternalPredicate([
...Object.keys(pkg.dependencies || {}),
...Object.keys(pkg.peerDependencies || {})
]),
plugins: [
filesize(),
babel({ plugins: ["external-helpers"] }),
env && replace({ "process.env.NODE_ENV": JSON.stringify(env) }),
min && uglify()
].filter(Boolean)
});
export default [
createConfig({
output: [
{ file: pkg.main, format: "cjs" },
{ file: pkg.module, format: "es" }
]
}),
createConfig({
output: { file: pkg.unpkg, format: "umd" },
env: "production",
min: true
})
];