-
Notifications
You must be signed in to change notification settings - Fork 120
/
rollup.config.js
57 lines (53 loc) · 1.52 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
import resolve from '@rollup/plugin-node-resolve';
import commonjs from '@rollup/plugin-commonjs';
import unassert from 'rollup-plugin-unassert';
import flowRemoveTypes from '@mapbox/flow-remove-types';
import {terser} from 'rollup-plugin-terser';
// Build es modules?
const esm = 'esm' in process.env;
import {fileURLToPath} from 'url';
const __dirname = fileURLToPath(new URL('.', import.meta.url));
const reviver = (key, value) => ['doc', 'example', 'sdk-support'].includes(key) ? undefined : value;
const config = [{
external: id => /ol(\/.+)?$/.test(id),
input: `${__dirname}/src/index.js`,
output: {
name: 'olms',
globals: esm ? undefined : id => /ol(\/.+)?$/.test(id) ? id.replace(/\.js$/, '').split('/').join('.') : id,
file: `${__dirname}/dist/${esm ? 'index.js' : 'olms.js'}`,
format: esm ? 'esm' : 'umd',
sourcemap: true,
plugins: esm ? undefined : [terser()]
},
plugins: [
{
name: 'flow-remove-types',
transform: (code) => ({
code: flowRemoveTypes(code).toString(),
map: null
})
},
{
name: 'json-min',
transform(code, id) {
if (id.endsWith('.json')) {
const json = JSON.parse(code);
const min = JSON.stringify(json, reviver);
code = `export default ${min}`;
return {
code,
map: null
};
}
return null;
}
},
unassert(),
resolve({
browser: true,
preferBuiltins: false
}),
commonjs()
]
}];
export default config;