Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@
"prerelease": "rm -rf dist/*; npm run build; zip -r dist.zip dist",
"pretest": "npm run lint",
"start": "vite",
"preview": "vite preview",
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

vite build && vite preview lets you view a production version of the site locally.

"test": "rollup -c ./rollup.test.config.js | tape-run --render='tap-spec'",
"watch": "rollup -cw"
},
Expand Down
1 change: 1 addition & 0 deletions public/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

<html lang="en">
<head>
<%= vite %>
<meta charset="utf-8" />

<title>Regl Scatterplot</title>
Expand Down
67 changes: 36 additions & 31 deletions vite.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,29 +16,35 @@ const chunks = [
'multiple-instances',
];

const pages = Object.fromEntries(
chunks.map((chunk) => [
chunk,
{ template: 'public/index.html', entry: `example/${chunk}.js` },
])
);
const chunkMapping = (fn) => Object.fromEntries(chunks.map((c) => [c, fn(c)]));

const manualChunks = (id) => {
if (id.includes('node_modules')) {
if (id.includes('apache-arrow')) {
return 'apache-arrow';
}
if (id.includes('d3')) {
return 'd3';
}
return 'vendor';
}
return undefined;
};
/**
* `vite-plugin-virtual-html-template` intercepts & handles requests for html
* from the client. Vite normally handles these requests and injects a script
* tag during dev (with a client runtime for HMR).
*
* The plugin uses `lodash.template` to render the HTML, so a `<%= vite %>`
* tag is replaced with the missing vite client during dev. In prod, nothing is
* added.
*/
const viteModule = '<script type="module" src="/@vite/client"></script>';

export default defineConfig({
export default ({ command }) => defineConfig({
base: './',
plugins: [virtualHtmlTemplate({ pages })],
plugins: [
virtualHtmlTemplate({
pages: chunkMapping((c) => ({ entry: `example/${c}.js` })),
data: { vite: command === 'build' ? '' : viteModule },
}),
{
name: 'simple-reload-template',
handleHotUpdate({ file, server }) {
if (file.includes('index.html')) {
server.ws.send({ type: 'full-reload' });
}
},
},
],
build: {
outDir: 'docs',
rollupOptions: {
Expand All @@ -47,15 +53,14 @@ export default defineConfig({
),
output: { manualChunks },
},
},
resolve: {
alias: {
/**
* vite pre-bundling (esbuild) can't be configured to
* resolve .fs/.vs in regl-line. This alias forces
* resolution with rollup, which avoids this error.
*/
'regl-line': '/node_modules/regl-line/src/index.js',
resolve: {
alias: {
/**
* vite pre-bundling (esbuild) can't be configured to
* resolve .fs/.vs in regl-line. This alias forces
* resolution with rollup, which avoids this error.
*/
'regl-line': '/node_modules/regl-line/src/index.js',
},
},
},
});
});