-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathrollup.config.mjs
More file actions
82 lines (77 loc) · 2.15 KB
/
rollup.config.mjs
File metadata and controls
82 lines (77 loc) · 2.15 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
import commonjs from '@rollup/plugin-commonjs';
import resolve from '@rollup/plugin-node-resolve';
import terser from '@rollup/plugin-terser';
import ignore from 'rollup-plugin-ignore';
import stripCode from 'rollup-plugin-strip-code';
let basicPlugins = [
stripCode({
start_comment: 'node-import',
end_comment: 'end-node-import'
}),
ignore(['xmlhttprequest']),
resolve({
jsnext: true,
main: true,
browser: true,
}),
commonjs({
include: './lib/*',
exclude: './lib/*//*'
})
];
let minifyPlugin = terser({
mangle: {
reserved: ['XMLHttpRequest']
}
});
export default args => {
let output = [];
let plugins = basicPlugins;
plugins.push(args.minify ? minifyPlugin : []);
let extension = args.minify ? '.min' : '';
if (args.mode === 'browser') {
output.push({
input: './lib/esm/index.js',
output: [
{
// IIFE for use in browsers
name: 'RandomOrgCore',
file: './lib/bundles/rdocore.iife' + extension + '.js',
format: 'iife',
sourcemap: 'inline'
},
{
// ES module for use in browsers
file: './lib/bundles/rdocore.es' + extension + '.js',
format: 'es',
exports: 'named',
sourcemap: 'inline'
}
],
plugins: plugins
});
}
if (args.mode === 'test') {
plugins.push(terser({
compress: {
conditionals: false
},
mangle: {
reserved: ['XMLHttpRequest']
}
}));
output.push({
// Converting the tests to run in the browser
input: './test/test.js',
output: {
file: './test/test.bundle.js',
format: 'es',
exports: 'named',
sourcemap: 'inline'
},
treeshake: false,
plugins: plugins
});
}
return output;
};