-
Notifications
You must be signed in to change notification settings - Fork 137
/
rollup.config.js
72 lines (63 loc) · 1.34 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
import { terser } from "rollup-plugin-terser";
import replace from '@rollup/plugin-replace';
import del from 'rollup-plugin-delete';
const { version: pkgVersion } = require('./package.json');
const version = process.env.NEXT_VERSION || pkgVersion;
export const terserConfig = {
compress: true,
mangle: true
};
export function bundle(type, name = 'jsep') {
let minify = false;
let format = type.replace(".min", () => {
minify = true;
return "";
});
let suffix = `.${type}`.replace(".esm", "");
let folder = format === 'esm' ? '' : `${format}/`;
return {
file: `dist/${folder}${name}${suffix}.js`,
name,
format,
sourcemap: type !== "esm",
exports: format === 'esm' ? 'named' : 'default',
plugins: [
minify? terser(terserConfig) : undefined,
]
};
}
const versionPlugin = replace({
"<%= version %>": version,
// Options:
preventAssignment: false,
delimiters: ['', ''],
});
export default [
{
input: "src/index.js",
output: [
bundle("esm"),
bundle("esm.min"),
],
plugins: [
del({ targets: 'dist/*' }),
versionPlugin,
],
},
{
input: "src/index.js",
output: [
bundle("iife"),
bundle("iife.min"),
bundle("cjs"),
bundle("cjs.min"),
],
plugins: [
versionPlugin,
replace({
'export class Jsep': 'class Jsep', // single default export
preventAssignment: false,
}),
],
},
];