forked from ableplayer/ableplayer
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathrollup.config.js
More file actions
158 lines (153 loc) · 4.94 KB
/
rollup.config.js
File metadata and controls
158 lines (153 loc) · 4.94 KB
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
import nodeResolve from '@rollup/plugin-node-resolve';
import commonjs from '@rollup/plugin-commonjs';
import terser from '@rollup/plugin-terser';
import strip from '@rollup/plugin-strip';
import pkg from './package.json' with { type: 'json' };
import json from '@rollup/plugin-json';
const getDefaultPlugins = () => {
return [nodeResolve(), commonjs(), json()];
}
const getTerserWithConfig = () => {
return terser({
ecma: 2022,
keep_fnames: true,
format: {
comments: /^!/,
},
compress: {
drop_console: ['log']
}
});
};
const getStripWithConfig = () => {
return strip({
functions: ['console.log'],
});
}
const nameVersion = `${pkg.name} V${pkg.version}`;
export default [
{
input: 'scripts/main.js',
plugins: getDefaultPlugins(),
external: ['jquery'],
output: [
{
name: 'AblePlayer',
file: 'build/ableplayer.js',
format: 'umd',
banner: `/*! ${nameVersion} - with DOMPurify included. Console logs enabled, for development */\n`,
sourcemap: true,
globals: {
jquery: 'jQuery',
},
},
{
name: 'AblePlayer',
file: 'build/ableplayer.min.js',
format: 'umd',
banner: `/*! ${nameVersion} - with DOMPurify included. Minified production bundle. */\n`,
sourcemap: true,
globals: {
jquery: 'jQuery',
},
plugins: [getTerserWithConfig()],
},
],
},
{
input: 'scripts/main.js',
plugins: [...getDefaultPlugins(), getStripWithConfig()],
external: ['jquery'],
output: [
{
name: 'AblePlayer',
file: 'build/ableplayer.dist.js',
format: 'umd',
banner: `/*! ${nameVersion} - with DOMPurify included. Console logs disabled, but not minified, for demos. */\n`,
sourcemap: true,
globals: {
jquery: 'jQuery',
},
},
],
},
{
input: 'scripts/main.js',
plugins: getDefaultPlugins(),
external: ['jquery', 'dompurify'],
output: [
{
name: 'AblePlayer',
file: 'build/separate-dompurify/ableplayer.js',
format: 'umd',
banner: `/*! ${nameVersion} - needs DOMPurify provided separately. Console logs enabled, for development */\n`,
sourcemap: true,
globals: {
jquery: 'jQuery',
dompurify: 'DOMPurify',
},
},
{
name: 'AblePlayer',
file: 'build/separate-dompurify/ableplayer.min.js',
format: 'umd',
banner: `/*! ${nameVersion} - needs DOMPurify provided separately. Minified production bundle. */\n`,
sourcemap: true,
globals: {
jquery: 'jQuery',
dompurify: 'DOMPurify',
},
plugins: [getTerserWithConfig()],
},
]
},
{
input: 'scripts/main.js',
plugins: [...getDefaultPlugins(), getStripWithConfig()],
external: ['jquery', 'dompurify'],
output: [
{
name: 'AblePlayer',
file: 'build/separate-dompurify/ableplayer.dist.js',
format: 'umd',
banner: `/*! ${nameVersion} - needs DOMPurify provided separately. Console logs disabled, but not minified, for demos. */\n`,
sourcemap: true,
globals: {
jquery: 'jQuery',
dompurify: 'DOMPurify',
},
},
]
},
{
// We still need to bundle a single ES module, to remove logs
// If we make the logging situation decide at runtime instead, we could simply expose the entry point directly
input: 'scripts/main.js',
plugins: [
...getDefaultPlugins(),
getStripWithConfig(),
],
external: [/node_modules/],
output: {
file: pkg.main,
banner: `/*! ${nameVersion} - ECMAScript module suitable for use in other bundlers. Console logs stripped out. */\n`,
format: 'esm',
sourcemap: true,
}
},
{
// This one is just for jest testing
input: 'scripts/validate.js',
plugins: [nodeResolve(), commonjs()],
external: ['dompurify'],
output: {
name: 'validate',
sourcemap: false,
file: 'build/test/validate.umd.js',
format: 'umd',
globals: {
dompurify: 'DOMPurify',
},
},
},
]