-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathrollup.config.js
156 lines (153 loc) · 3.77 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
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
import resolve from '@rollup/plugin-node-resolve';
import commonjs from '@rollup/plugin-commonjs';
import babel from '@rollup/plugin-babel';
import json from '@rollup/plugin-json';
import replace from '@rollup/plugin-replace';
import terser from '@rollup/plugin-terser';
import dotenv from 'dotenv';
import { visualizer } from "rollup-plugin-visualizer";
const envFile = process.env.NODE_ENV === 'production' ? '.env.production' : '.env.development';
let envVars = process.env.NODE_ENV === 'production' ? { API_URL: 'https://api' } : dotenv.config({ path: envFile }).parsed;
const basePlugins = [
resolve(),
commonjs(),
json(),
replace({
preventAssignment: true,
values: Object.keys(envVars).reduce((prev, next) => {
prev[`process.env.${next}`] = JSON.stringify(envVars[next]);
return prev;
}, {}),
}),
visualizer(),
terser(),
];
const external = ['maplibre-gl', 'ol', 'ol-mapbox-style', 'pbf', 'rbush', 'ieee754', /^ol\/.+$/];
const globals = {
'this': 'this',
'maplibre-gl': 'maplibregl',
'rbush': 'RBush',
'pbf': 'PBF',
'ol-mapbox-style': 'olms',
'ol': 'ol',
'ol/Map': 'Map',
'ol/control': 'control',
'ol/interaction': 'interaction',
'ol/proj': 'proj',
'ol/layer': 'layer',
'ol/source': 'source',
'ol/format': 'format',
'ol/View': 'View',
'ol/extent': 'extent'
};
const polyfillBabel = babel({
babelHelpers: 'bundled',
exclude: [/\/core-js\//],
presets: [
['@babel/preset-env', {
targets: [
"> 0.2%",
"ie >= 9",
"not op_mini all"
],
useBuiltIns: 'usage',
corejs: 3,
}],
],
});
const standardBabel = babel({
babelHelpers: 'bundled',
exclude: [/\/core-js\//],
presets: [
['@babel/preset-env', {
targets: [
"> 0.5%",
"not dead",
"not op_mini all"
],
useBuiltIns: 'usage',
corejs: 3,
}],
],
});
export default [
{
input: './index.maplibre.js',
output: [{
file: 'dist/index.js',
format: 'es',
name: 'slpy',
sourcemap: true,
globals
}],
external,
plugins: [
...basePlugins,
standardBabel,
]
},
{
input: './index.openlayers.js',
output: [{
file: 'dist/index.openlayers.js',
format: 'es',
name: 'slpy',
sourcemap: true,
globals
}],
external,
plugins: [
...basePlugins,
standardBabel,
]
},
{
input: './index.umd.js',
output: {
file: 'dist/slpy.js',
format: 'umd',
name: 'slpy',
sourcemap: true,
globals,
},
external,
plugins: [
...basePlugins,
standardBabel,
]
},
{
input: './index.polyfilled.js',
output: {
file: 'dist/slpy.polyfilled.js',
format: 'umd',
name: 'slpy',
sourcemap: true,
globals,
},
context: 'window',
moduleContext: 'window',
external,
treeshake: false,
plugins: [
...basePlugins,
polyfillBabel,
],
},
{
input: './index.polyfills.js',
output: {
file: 'dist/slpy.polyfills.js',
format: 'umd',
sourcemap: true,
},
context: 'window',
moduleContext: 'window',
external,
treeshake: false,
plugins: [
...basePlugins,
polyfillBabel,
],
}
];