-
Notifications
You must be signed in to change notification settings - Fork 7
/
Copy pathrollup.config.mjs
74 lines (64 loc) · 1.61 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
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
// Plugins
import { typescriptPaths as paths } from 'rollup-plugin-typescript-paths';
import { nodeResolve as node } from '@rollup/plugin-node-resolve';
import { minify, swc } from 'rollup-plugin-swc3';
import hermes from '@unbound-mod/rollup-plugin';
import replace from '@rollup/plugin-replace';
import { execSync } from 'child_process';
import json from '@rollup/plugin-json';
import { readFileSync } from 'fs';
const revision = (() => {
try {
return execSync('git rev-parse --short HEAD').toString().trim();
} catch {
return 'N/A';
}
})();
const preinit = readFileSync('./preinit.js');
// These must exist in
const importsMap = {
'react': 'window.React',
'react-native': 'window.ReactNative'
};
/** @type {import('rollup').RollupOptions} */
const config = {
input: 'src/index.ts',
external: Object.keys(importsMap),
output: [
{
footer: '//# sourceURL=unbound',
file: 'dist/unbound.js',
format: 'iife',
inlineDynamicImports: true,
strict: false,
globals: importsMap
}
],
plugins: [
paths({ preserveExtensions: true, nonRelative: !(process.platform === 'darwin' || process.platform === 'linux') }),
node(),
json(),
replace({ preventAssignment: true, __VERSION__: revision }),
swc({ tsconfig: false }),
{
name: 'iife',
renderChunk(code) {
return `(() => {
try {
${preinit}
${code}
} catch(error) {
alert('Unbound failed to initialize: ' + error.stack);
}
})();`;
}
},
minify({ compress: true, mangle: true }),
hermes(),
],
onwarn(warning, warn) {
if (warning.code === 'EVAL') return;
warn(warning);
}
};
export default config;