This repository has been archived by the owner on Nov 12, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 14
/
rollup.config.cjs
116 lines (95 loc) · 2.32 KB
/
rollup.config.cjs
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
const filesize = require('rollup-plugin-filesize');
const server = require('rollup-plugin-serve');
const { terser } = require('rollup-plugin-terser');
const strip = require('@rollup/plugin-strip');
const { babel } = require('@rollup/plugin-babel');
const copy = require('rollup-plugin-copy');
const livereload = require('rollup-plugin-livereload');
const pkg = require('./package.json');
const isProduction = process.env.NODE_ENV === 'production';
// Extract the package name from the scoped name in package.json
const pkgName = pkg.name.replace(/^@.*\//u, '');
const banner = `/*!
* ${pkg.name} v${pkg.version}
*/`;
const devPlugins = (serve) => {
return !isProduction && serve
? [
// Live reloading
livereload(),
// Copy source file to dist/src to reference during dev
copy({
targets: [{ src: 'src/jlottie.js', dest: 'dist/src' }],
}),
// Serve builds
server({
contentBase: ['public', 'dist', 'tests/public/test_files'],
open: true,
host: 'localhost',
port: 8300,
}),
]
: [];
};
const createConfig = (options) => {
const { fileExt, format, minify = false, serve = false, transpile = false } = options;
return {
input: 'src/jlottie.js',
treeshake: false,
output: {
name: 'jlottie',
format,
file: `dist/${pkgName}${fileExt}`,
banner,
sourcemap: true,
},
plugins: [
transpile &&
babel({
babelHelpers: 'bundled',
}),
isProduction && strip(),
minify && terser(),
filesize(),
...devPlugins(serve),
],
};
};
module.exports = [
// UMD build for the browser
{
fileExt: '.js',
format: 'umd',
serve: true,
transpile: true,
},
// Minified UMD build for the browser
{
fileExt: '.min.js',
format: 'umd',
minify: true,
transpile: true,
},
// CJS build for the browser
{
fileExt: '.cjs.js',
format: 'cjs',
},
// Minified CJS build for the browser
{
fileExt: '.min.cjs.js',
format: 'cjs',
minify: true,
},
// ESM build for the browser
{
fileExt: '.esm.js',
format: 'es',
},
// Minified ESM build for the browser
{
fileExt: '.min.esm.js',
format: 'es',
minify: true,
},
].map((config) => createConfig(config));