-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathrollup.config.mjs
79 lines (71 loc) · 1.85 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
75
76
77
78
79
import terser from '@rollup/plugin-terser';
import jscc from 'rollup-plugin-jscc';
import json from '@rollup/plugin-json';
import { readFileSync } from 'fs';
import strip from '@rollup/plugin-strip';
import { nodeResolve } from '@rollup/plugin-node-resolve';
const pkg = JSON.parse(readFileSync(new URL('./package.json', import.meta.url), 'utf8'));
const joltPkg = JSON.parse(readFileSync(new URL('./node_modules/jolt-physics/package.json', import.meta.url), 'utf8'));
const STRIP_FUNCTIONS = [
'Debug.log',
'Debug.logOnce',
'Debug.warn',
'Debug.warnOnce',
'Debug.error',
'Debug.errorOnce',
'Debug.assert',
'Debug.checkRange',
'Debug.checkInt',
'Debug.checkUint',
'Debug.checkFloat',
'Debug.checkFloatPositive',
'Debug.checkBool',
'Debug.checkVec',
'Debug.checkVecPositive',
'Debug.checkQuat',
'Debug.checkSpringSettings',
'Debug.verifyProperties'
];
const versions = {
_VERSION: JSON.stringify(pkg.version),
_JOLT_VERSION: JSON.stringify(joltPkg.version)
};
const jscOptsProd = {
values: {
...versions,
_DEBUG: 1
},
asloader: false,
keepLines: true
};
const jscOptsDev = {
...jscOptsProd,
values: {
...versions,
_DEBUG: 0
}
};
export default (args) => {
const isDev = args.config_dev;
const file = isDev ? 'dist/physics.dbg.mjs' : 'dist/physics.min.mjs';
const plugins = [json(), nodeResolve()];
if (isDev) {
plugins.push(jscc(jscOptsProd));
} else {
plugins.push(
strip({ functions: STRIP_FUNCTIONS }),
jscc(jscOptsDev),
terser()
);
}
return {
input: 'src/index.mjs',
output: {
file,
format: 'es',
sourcemap: isDev ? 'inline' : false
},
external: ['playcanvas'],
plugins
};
};