-
Notifications
You must be signed in to change notification settings - Fork 5
/
vite.config.ts
123 lines (113 loc) · 2.82 KB
/
vite.config.ts
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
import { svelte } from "@sveltejs/vite-plugin-svelte";
import process from "node:process";
import { sveltePreprocess } from "svelte-preprocess";
import { BuildOptions, defineConfig } from "vite";
const libs = {
leaflet: {
fileName: "leaflet",
entry: ["src/leaflet.ts"],
name: "leafletMaptilerGeocoder",
},
maplibre: {
fileName: "maplibregl",
entry: ["src/maplibregl.ts"],
name: "maplibreglMaptilerGeocoder",
},
maptilersdk: {
fileName: "maptilersdk",
entry: ["src/maptilersdk.ts"],
name: "maptilersdkMaptilerGeocoder",
},
openlayers: {
fileName: "openlayers",
entry: ["src/openlayers.ts"],
name: "openlayersMaptilerGeocoder",
},
react: {
fileName: "react",
entry: ["src/react.ts"],
name: "reactMaptilerGeocoder",
},
vanilla: {
fileName: "vanilla",
entry: ["src/vanilla.ts"],
name: "maptilerGeocoder",
},
"leaflet-controller": {
fileName: "leaflet-controller",
entry: ["src/leaflet-controller.ts"],
name: "leafletMaptilerGeocodingController",
},
"maplibregl-controller": {
fileName: "maplibregl-controller",
entry: ["src/maplibregl-controller.ts"],
name: "maplibreglMaptilerGeocodingController",
},
"openlayers-controller": {
fileName: "openlayers-controller",
entry: ["src/openlayers-controller.ts"],
name: "openlayersMaptilerGeocodingController",
},
};
let lib: BuildOptions["lib"];
let rollupOptions: BuildOptions["rollupOptions"];
const flavour = process.env.FLAVOUR;
if (flavour) {
if (!(flavour in libs)) {
throw new Error("invalid FLAVOUR");
}
lib = libs[flavour as keyof typeof libs];
rollupOptions = {
external: [
"@maptiler/sdk",
"maplibre-gl",
"leaflet",
"react",
"react-dom",
/^ol(\/.*)?/,
],
output: [
{
format: "es",
entryFileNames: "[name].js",
chunkFileNames: "[name].js",
assetFileNames: "[name].[ext]",
},
{
name: lib.name,
format: "umd",
entryFileNames: "[name].umd.js",
chunkFileNames: "[name].umd.js",
assetFileNames: "[name].[ext]",
// Provide global variables to use in the UMD build for externalized deps
globals(name) {
const global = {
"@maptiler/sdk": "maptilersdk",
"maplibre-gl": "maplibregl",
leaflet: "L",
react: "React",
"react-dom": "ReactDOM",
}[name];
return (
global ?? (name.startsWith("ol") ? name.replace(/\//g, ".") : "")
);
},
},
],
};
}
// https://vitejs.dev/config/
export default defineConfig({
plugins: [
svelte({
preprocess: sveltePreprocess(),
}),
],
publicDir: "public",
build: {
sourcemap: true,
emptyOutDir: false,
lib,
rollupOptions,
},
});