-
Notifications
You must be signed in to change notification settings - Fork 18
/
vite.config.js
54 lines (50 loc) · 1.42 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
49
50
51
52
53
54
import * as path from 'node:path';
import { defineConfig } from 'vite';
import react from '@vitejs/plugin-react';
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: {
outDir: 'out',
assetsDir: '',
sourcemap: true,
rollupOptions: {
output: {
minifyInternalExports: false,
manualChunks: {
vizarr: [path.resolve(__dirname, 'src/index.tsx')],
},
},
},
},
resolve: {
alias: {
'@hms-dbmi/vizarr': path.resolve(__dirname, 'src/index.tsx'),
},
},
server: {
open: `?source=${source}`,
},
});