-
Notifications
You must be signed in to change notification settings - Fork 11
/
Copy pathrollup.config.js
104 lines (97 loc) · 2.22 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
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
import typescript from 'rollup-plugin-typescript2';
import json from '@rollup/plugin-json';
import terser from '@rollup/plugin-terser';
import commonjs from '@rollup/plugin-commonjs';
import postcss from 'rollup-plugin-postcss';
import { nodeResolve } from '@rollup/plugin-node-resolve';
// remove typescript declarations from file in the CDN output folder
// (only keep the output file specified in the rollup config)
const onlyEmitFile = () => ({
name: 'only-emit-file',
generateBundle(outputOptions, bundle) {
const outputFile = outputOptions.file;
const outputFileName = outputFile.split('/').pop();
for (const fileName in bundle) {
// remove file if doesn't match "file" in config
if (fileName !== outputFileName && !fileName.endsWith('.css')) {
delete bundle[fileName];
}
}
}
});
export default [
// ES Module (written to /dist)
{
input: 'src/index.ts',
output: [
{
file: 'dist/radar.js',
format: 'esm',
sourcemap: true,
},
],
external: ['maplibre-gl'],
plugins: [
typescript(),
nodeResolve(),
commonjs(),
json(),
postcss({
extract: 'radar.css',
minimize: true,
}),
],
},
// IIFE (browser bundles, written to /cdn)
{
input: 'src/index.ts',
output: [
{
file: 'cdn/radar.js',
format: 'iife',
name: 'Radar',
plugins: [onlyEmitFile()],
},
{
file: 'cdn/radar.min.js',
format: 'iife',
name: 'Radar',
plugins: [terser(), onlyEmitFile()],
},
],
plugins: [
typescript(),
nodeResolve(),
commonjs(),
json(),
postcss({
extract: 'radar.css',
minimize: true,
}),
],
},
// IIFE (core SDK feature - no maps)
{
input: 'src/api.ts',
output: [
{
file: 'cdn/radar-core.js',
format: 'iife',
name: 'Radar',
plugins: [onlyEmitFile()],
},
{
file: 'cdn/radar-core.min.js',
format: 'iife',
name: 'Radar',
plugins: [terser(), onlyEmitFile()],
},
],
plugins: [
typescript(),
nodeResolve(),
commonjs(),
json(),
],
}
];