-
-
Notifications
You must be signed in to change notification settings - Fork 2.9k
/
rollup.config.js
205 lines (195 loc) · 4.46 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
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
import { nodeResolve } from '@rollup/plugin-node-resolve';
import { terser } from 'rollup-plugin-terser';
import babel from '@rollup/plugin-babel';
import {version} from './package.json'
const injectVersion = (options = {}) => {
return {
name: 'inject-version',
renderChunk: (code) => {
return code.replace('[[BM_VERSION]]', version)
},
}
}
const addNavigatorValidation = (options = {}) => {
return {
name: 'inject-version',
renderChunk: (code) => {
return '(typeof navigator !== "undefined") && ' + code
},
}
}
const noTreeShakingForStandalonePlugin = () => {
return {
name: 'no-treeshaking-for-standalone',
transform(code) {
// This is very fast but can produce lots of false positives.
// Use a good regular expression or parse an AST and analyze scoping to improve as needed.
if (code.indexOf('__[STANDALONE]__') >= 0) return {moduleSideEffects: 'no-treeshake'};
}
}
}
const destinationBuildFolder = 'build/player/';
const builds = [
{
input: 'player/js/modules/full.js',
dest: `${destinationBuildFolder}`,
file: 'lottie.min.js',
esm: true,
},
{
input: 'player/js/modules/full.js',
dest: `${destinationBuildFolder}`,
file: 'lottie.js',
esm: false,
skipTerser: true,
},
{
input: 'player/js/modules/svg_light.js',
dest: `${destinationBuildFolder}`,
file: 'lottie_light.min.js',
esm: true,
},
{
input: 'player/js/modules/svg_light.js',
dest: `${destinationBuildFolder}`,
file: 'lottie_light.js',
esm: false,
skipTerser: true,
},
{
input: 'player/js/modules/svg.js',
dest: `${destinationBuildFolder}`,
file: 'lottie_svg.min.js',
esm: true,
},
{
input: 'player/js/modules/svg.js',
dest: `${destinationBuildFolder}`,
file: 'lottie_svg.js',
esm: false,
skipTerser: true,
},
{
input: 'player/js/modules/canvas.js',
dest: `${destinationBuildFolder}`,
file: 'lottie_canvas.min.js',
esm: true,
},
{
input: 'player/js/modules/canvas_light.js',
dest: `${destinationBuildFolder}`,
file: 'lottie_light_canvas.js',
esm: false,
skipTerser: true,
},
{
input: 'player/js/modules/canvas_light.js',
dest: `${destinationBuildFolder}`,
file: 'lottie_light_canvas.min.js',
esm: true,
},
{
input: 'player/js/modules/canvas.js',
dest: `${destinationBuildFolder}`,
file: 'lottie_canvas.js',
esm: false,
skipTerser: true,
},
{
input: 'player/js/modules/html_light.js',
dest: `${destinationBuildFolder}`,
file: 'lottie_light_html.min.js',
esm: true,
},
{
input: 'player/js/modules/html_light.js',
dest: `${destinationBuildFolder}`,
file: 'lottie_light_html.js',
esm: false,
skipTerser: true,
},
{
input: 'player/js/modules/html.js',
dest: `${destinationBuildFolder}`,
file: 'lottie_html.min.js',
esm: true,
},
{
input: 'player/js/modules/html.js',
dest: `${destinationBuildFolder}`,
file: 'lottie_html.js',
esm: false,
skipTerser: true,
},
];
const plugins = [
nodeResolve(),
babel({
babelHelpers: 'runtime',
skipPreflightCheck: true,
}),
// noTreeShakingForStandalonePlugin(),
injectVersion(),
addNavigatorValidation(),
]
const pluginsWithTerser = [
...plugins,
terser(),
]
const UMDModule = {
output: {
format: 'umd',
name: 'lottie', // this is the name of the global object
esModule: false,
exports: 'default',
sourcemap: false,
compact: false,
},
treeshake: false,
};
const ESMModule = {
plugins: [nodeResolve()],
treeshake: false,
output: [
{
format: 'esm',
exports: 'named',
},
{
format: 'cjs',
exports: 'named',
},
],
};
const exports = builds.reduce((acc, build) => {
const builds = [];
builds.push({
...UMDModule,
plugins: !build.skipTerser ? pluginsWithTerser : plugins,
input: build.input,
output: {
...UMDModule.output,
file: `${build.dest}${build.file}`,
}
});
if (build.esm) {
builds.push({
...ESMModule,
input: build.input,
output: [
{
...ESMModule.output[0],
file: 'dist/esm/' + build.file,
file: `${destinationBuildFolder}esm/${build.file}`,
},
{
...ESMModule.output[1],
file: `${destinationBuildFolder}cjs/${build.file}`,
}
]
});
}
acc = acc.concat(builds);
return acc;
}, []);
export default exports;