-
-
Notifications
You must be signed in to change notification settings - Fork 58
/
rollup.config.js
149 lines (142 loc) · 3.21 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
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
import babel from "rollup-plugin-babel";
import external from "rollup-plugin-peer-deps-external";
import resolve from "@rollup/plugin-node-resolve";
import commonjs from "@rollup/plugin-commonjs";
import postcss from "rollup-plugin-postcss";
import autoprefixer from "autoprefixer";
import { terser } from "rollup-plugin-terser";
import dts from "rollup-plugin-dts";
import packageJSON from "./package.json";
/**
* We are using 'build/compiled/index.js' instead of 'src/index.tsx'
* because we need to compile the code first.
*
* We could've used the '@rollup/plugin-typescript' but that plugin
* doesn't allow us to rename the files on output. So we decided to
* compile the code and after that to run the rollup command using
* the index file generated by the compilation.
*
* @type {string}
*/
const input = "./compiled/index.js";
/**
* Get the extension for the minified files
* @param pathToFile
* @return string
*/
const minifyExtension = (pathToFile) => pathToFile.replace(/\.js$/, ".min.js");
/**
* Get the extension for the TS definition files
* @param pathToFile
* @return string
*/
const dtsExtension = (pathToFile) => pathToFile.replace(".js", ".d.ts");
/**
* Definition of the common plugins used in the rollup configurations
*/
const reusablePluginList = [
postcss({
plugins: [autoprefixer],
}),
babel({
exclude: "node_modules/**",
}),
external(),
resolve(),
commonjs(),
];
/**
* Definition of the rollup configurations
*/
const exports = {
cjs: {
input,
output: {
file: packageJSON.main,
format: "cjs",
sourcemap: true,
exports: "named",
},
external: ["lottie-web"],
plugins: reusablePluginList,
},
cjs_min: {
input,
output: {
file: minifyExtension(packageJSON.main),
format: "cjs",
exports: "named",
},
external: ["lottie-web"],
plugins: [...reusablePluginList, terser()],
},
umd: {
input,
output: {
file: packageJSON.browser,
format: "umd",
sourcemap: true,
name: "lottie-react",
exports: "named",
globals: {
react: "React",
"lottie-web": "Lottie",
},
},
external: ["lottie-web"],
plugins: reusablePluginList,
},
umd_min: {
input,
output: {
file: minifyExtension(packageJSON.browser),
format: "umd",
exports: "named",
name: "lottie-react",
globals: {
react: "React",
"lottie-web": "Lottie",
},
},
external: ["lottie-web"],
plugins: [...reusablePluginList, terser()],
},
es: {
input,
output: {
file: packageJSON.module,
format: "es",
sourcemap: true,
exports: "named",
},
external: ["lottie-web"],
plugins: reusablePluginList,
},
es_min: {
input,
output: {
file: minifyExtension(packageJSON.module),
format: "es",
exports: "named",
},
external: ["lottie-web"],
plugins: [...reusablePluginList, terser()],
},
dts: {
input: dtsExtension(input),
output: {
file: packageJSON.types,
format: "es",
},
plugins: [dts()],
},
};
export default [
exports.cjs,
exports.cjs_min,
exports.umd,
exports.umd_min,
exports.es,
exports.es_min,
exports.dts,
];