-
Notifications
You must be signed in to change notification settings - Fork 4
/
rollup.config.js
87 lines (83 loc) · 1.78 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
import babel from "rollup-plugin-babel";
import commonjs from "rollup-plugin-commonjs";
import resolve from "rollup-plugin-node-resolve";
import autoExternal from "rollup-plugin-auto-external";
import replace from "rollup-plugin-replace";
import { uglify } from "rollup-plugin-uglify";
import dotenv from "rollup-plugin-dotenv";
import pkg from "./package.json";
const ensureArray = maybeArr =>
Array.isArray(maybeArr) ? maybeArr : [maybeArr];
const globals = {
"@livechat/mitt": "mitt",
"@livechat/platform-client": "platformClient",
"@livechat/data-utils": "dataUtils"
};
const createConfig = ({
input = "src/index.js",
output,
env,
minimalize = false,
useGlobals = false
} = {}) => ({
input,
output: ensureArray(output).map(format =>
Object.assign({}, format, {
name: "ChatSDK",
globals: useGlobals && globals
})
),
plugins: [
autoExternal(),
dotenv(),
resolve({ browser: true }),
babel({ exclude: "node_modules/**" }),
commonjs(),
env &&
replace({
"process.env.NODE_ENV": JSON.stringify(env)
}),
minimalize &&
uglify({
compress: {
pure_getters: true,
unsafe: true,
unsafe_comps: true
}
})
].filter(Boolean),
treeshake: {
propertyReadSideEffects: false
}
});
export default [
createConfig({
output: [
{
file: pkg.module,
format: "esm"
},
{
file: pkg.cjs,
format: "cjs"
}
]
}),
createConfig({
env: "development",
useGlobals: true,
output: {
file: pkg.main,
format: "umd"
}
}),
createConfig({
env: "production",
useGlobals: true,
minimalize: true,
output: {
file: pkg.main.replace(/\.js$/, ".min.js"),
format: "umd"
}
})
];