-
Notifications
You must be signed in to change notification settings - Fork 93
/
rollup.config.js
83 lines (73 loc) · 1.94 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
import typescript from "rollup-plugin-typescript2";
import resolve from "rollup-plugin-node-resolve";
import commonjs from "rollup-plugin-commonjs";
import uglify from "rollup-plugin-uglify";
import filesize from "rollup-plugin-filesize";
const format = process.env.NODE_ENV;
const isUmd = format === "umd";
const REACT = "react";
const PREACT = "preact";
function getFileName(file) {
if (isUmd) {
return `${file}.min.js`;
}
return `${file}.js`;
}
function getGlobals(file) {
if (isUmd) {
if (file.startsWith(REACT)) {
return { react: "React" };
} else if (file.startsWith(PREACT)) {
return { preact: PREACT };
}
return {};
}
return {};
}
function getExternals(file) {
if (file.startsWith(REACT)) {
return [REACT];
} else if (file.startsWith(PREACT)) {
return [PREACT];
}
return [];
}
function getConfig(input, file) {
const tsconfig = input.includes(PREACT)
? "./src/preact/tsconfig.json"
: "tsconfig.json";
const conf = {
input,
name: "redux-zero",
sourcemap: false,
external: getExternals(file),
output: {
file: getFileName(file),
format,
globals: getGlobals(file)
},
plugins: [
typescript({ useTsconfigDeclarationDir: true, tsconfig }),
resolve({
jsnext: true,
main: true,
browser: true
}),
commonjs()
]
};
isUmd && conf.plugins.push(uglify(), filesize());
return conf;
}
const config = [
getConfig("./src/index.ts", "dist/redux-zero"),
getConfig("./src/preact/index.ts", "preact/index"),
getConfig("./src/react/index.ts", "react/index"),
getConfig("./src/svelte/index.ts", "svelte/index"),
getConfig("./src/vue/index.ts", "vue/index"),
getConfig("./src/middleware/index.ts", "middleware/index"),
getConfig("./src/utils/index.ts", "utils/index"),
getConfig("./src/devtools/index.ts", "devtools/index"),
getConfig("./src/types/index.ts", "types/index")
];
export default config;