forked from jgraph/mxgraph
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathrollup.config.mjs
57 lines (48 loc) · 1.18 KB
/
rollup.config.mjs
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
import fs from 'fs';
import path from 'path';
import terser from '@rollup/plugin-terser';
export default {
input: 'javascript/src/js/mxClient.js',
output: [
{
file: 'javascript/mxClient.js',
format: 'cjs',
strict: false
},
{
file: 'javascript/mxClient.min.js',
format: 'cjs',
strict: false,
plugins: [terser()]
}
],
plugins: [handleDependencies()],
treeshake: false
}
function handleDependencies() {
return {
name: 'handleDependencies',
transform(content) {
const deps = getDependencies(content);
const combined = combineDependencies(deps);
return combined
}
}
}
function getDependencies(content) {
let deps = content
.match(/mxClient\.include\([^"']+["'](.*?)["']/gi)
.map(str => str.match(/mxClient\.include\([^"']+["'](.*?)["']/)[1]);
deps = ['./js/mxClient.js'].concat(deps.slice(0));
return deps;
}
function combineDependencies(dependencies) {
let code = '';
for (const file of dependencies) {
const filePath = path.join(process.cwd(), '/javascript/src/', file);
const content = fs.readFileSync(filePath, 'utf-8');
code += content;
}
code = code.replace(/mxClient\.include\([^"']+["'](.*?)["'][)];?\n?/gi, '');
return code;
}