-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathrollup.config.js
72 lines (64 loc) · 1.89 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 path from 'path';
import replace from '@rollup/plugin-replace';
let files = [
['libdeflate', 'LibDeflate'],
['example/basic', 'ExampleBasic'],
];
let importpath = path.join(__dirname, 'build/libdeflate');
let nodemain_cjs = classname => `
if (require !== undefined && require.main === module) {
${classname}.node_main(process);
}`;
let nodemain_mjs = classname => `
if (process != undefined) {
(async () => {
let path = await import('path');
let url = await import('url');
if (path.resolve(process.argv[1]) === url.fileURLToPath(import.meta.url)) {
${classname}.node_main(process);
}
})()
}`;
let internal_footer = footer => ({
transform: (code, id) => {
if (id == importpath + ".js") {
return null;
}
return code + footer;
}
})
let result = [];
for (const [file, classname] of files) {
result.push({
input: `build/${file}.js`,
output: {
file: `dist/${file}.mjs`,
format: 'esm',
paths: { [importpath] : '../libdeflate.mjs' },
},
plugins:[
replace({
'require': 'await import',
'__dirname': 'path.dirname((await import(\'url\')).fileURLToPath(import.meta.url))'
}),
internal_footer(nodemain_mjs(classname)),
],
external: ['path', 'fs', 'url', '../libdeflate']
});
result.push({
input: `build/${file}.js`,
output: {
file: `dist/${file}.js`,
format: 'umd',
exports: 'default',
name: classname,
paths: { [importpath] : '../libdeflate.js' },
globals: { [importpath] : 'LibDeflate' },
},
plugins:[
internal_footer(nodemain_cjs(classname)),
],
external: ['path', 'fs', 'url', '../libdeflate']
});
}
export default result;