Skip to content

Commit

Permalink
chore: manual chunks
Browse files Browse the repository at this point in the history
  • Loading branch information
manzt committed Oct 19, 2023
1 parent 7ea05dc commit 61a9471
Show file tree
Hide file tree
Showing 3 changed files with 37 additions and 16 deletions.
3 changes: 1 addition & 2 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,7 @@ npm-debug.log*
yarn-debug.log*
yarn-error.log*

.next/*
out/*
dist/

example/*.zarr
example/.ipynb_checkpoints/*
Expand Down
2 changes: 1 addition & 1 deletion main.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import * as vizarr from '@hms-dbmi/vizarr';
import * as vizarr from './src/index';
import debounce from 'just-debounce-it';

async function initImjoy(viewer: vizarr.VizarrViewer) {
Expand Down
48 changes: 35 additions & 13 deletions vite.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,26 +5,48 @@ 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()],
plugins: [
react(),
writeEntryPoint('index.js', /^vizarr-/),
],
base: process.env.VIZARR_PREFIX || './',
build: {
outDir: 'out',
assetsDir: '',
minify: false,
lib: {
entry: {
main: path.resolve(__dirname, 'index.html'),
index: path.resolve(__dirname, 'src/index.tsx'),
rollupOptions: {
output: {
manualChunks: {
vizarr: [path.resolve(__dirname, 'src/index.tsx')],
},
},
formats: ['es'],
}
},
},
resolve: {
alias: {
zarr: 'zarr/core',
'@hms-dbmi/vizarr': path.resolve(__dirname, 'src/index.tsx'),
},
alias: { zarr: 'zarr/core' },
},
server: {
open: `?source=${source}`,
Expand Down

0 comments on commit 61a9471

Please sign in to comment.