forked from hms-dbmi/vizarr
-
Notifications
You must be signed in to change notification settings - Fork 0
/
vite.config.js
48 lines (44 loc) · 1.29 KB
/
vite.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
import * as path from "node:path";
import react from "@vitejs/plugin-react";
import { defineConfig } from "vite";
const source = process.env.VIZARR_DATA || "https://uk1s3.embassy.ebi.ac.uk/idr/zarr/v0.1/6001253.zarr";
/**
* Writes a new entry point that exports contents of an existing chunk.
* @param {string} entryPointName - Name of the new entry point
* @param {RegExp} chunkName - Name of the existing chunk
*/
function writeEntryPoint(entryPointName, chunkName) {
return {
name: "write-entry-point",
async generateBundle(_, bundle) {
const chunk = Object.keys(bundle).find((key) => key.match(chunkName));
if (!chunk) {
throw new Error(`Could not find chunk matching ${chunkName}`);
}
bundle[entryPointName] = {
fileName: entryPointName,
type: "chunk",
code: `export * from './${chunk}';`,
};
},
};
}
export default defineConfig({
plugins: [react(), writeEntryPoint("index.js", /^vizarr-/)],
base: process.env.VIZARR_PREFIX || "./",
build: {
assetsDir: "",
sourcemap: true,
rollupOptions: {
output: {
minifyInternalExports: false,
manualChunks: {
vizarr: [path.resolve(__dirname, "src/index.tsx")],
},
},
},
},
server: {
open: `?source=${source}`,
},
});