-
Notifications
You must be signed in to change notification settings - Fork 46
/
Copy pathrollup.config.js
80 lines (74 loc) · 2.23 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
73
74
75
76
77
78
79
80
import { defineConfig } from 'rollup';
import { nodeResolve } from '@rollup/plugin-node-resolve';
import commonjs from '@rollup/plugin-commonjs';
import json from '@rollup/plugin-json';
import MagicString from 'magic-string';
export default defineConfig({
input: 'bin/clever.js',
output: {
file: 'build/clever.cjs',
format: 'cjs',
sourcemap: 'inline',
},
// This dependency is only pulled in when building on MacOS (see https://github.com/CleverCloud/clever-tools/issues/864)
// It's a binary file and it shouldn't be parsed by rollup, only copied.
// We exclude it from the bundle because it's a dependency that is pulled by `curlconverter` but we don't actually need it.
external: ['fsevents'],
plugins: [
{
transform (code, id) {
// formidable (used by superagent) hijacks require :-(
if (id.includes('/node_modules/formidable/')) {
const ms = new MagicString(code);
ms.replaceAll(
'if (global.GENTLY) require = GENTLY.hijack(require);',
'',
);
return {
code: ms.toString(),
map: ms.generateMap(),
};
}
// for update notifier
if (id.includes('/node_modules/update-notifier/')) {
const ms = new MagicString(code);
ms
.replaceAll(
`const importLazy = require('import-lazy')(require);`,
'',
)
.replaceAll(
/const ([^ ]+) = importLazy\(\'([^']+)\'\);/g,
'const $1_ = require(\'$2\'); const $1 = () => $1_',
);
return {
code: ms.toString(),
map: ms.generateMap(),
};
}
// for ws peer deps
if (id.includes('/node_modules/ws/')) {
const ms = new MagicString(code);
ms
.replaceAll(
'require(\'bufferutil\')',
'null',
)
.replaceAll(
'require(\'utf-8-validate\')',
'{}',
);
return {
code: ms.toString(),
map: ms.generateMap(),
};
}
},
},
commonjs(),
nodeResolve({
preferBuiltins: true,
}),
json(),
],
});