Skip to content

Conversation

mbostock
Copy link
Member

@mbostock mbostock commented Nov 27, 2023

Fixes #61. Fixes #233 (trivally; we can add tree shaking if we want to cut code size further). The diff is a bit large, but there are only a couple trivial changes to the code to break it up into more manageable files.

This uses a dedicated entry point for preview such that in build we don’t include the open function, reducing code size.

In followup PRs, I would like to:

  • Add unit tests for client code, as much as possible
  • Port the client code to TypeScript for additional type safety
  • Use npm: protocol imports instead of jsDelivr URLs?

@mbostock mbostock force-pushed the mbostock/rollup-client branch 3 times, most recently from ec180d5 to ab4bfa2 Compare November 28, 2023 03:20
@mbostock mbostock force-pushed the mbostock/rollup-client branch from ab4bfa2 to dfa505a Compare November 28, 2023 03:21
@mbostock mbostock marked this pull request as ready for review November 28, 2023 03:27
@mbostock mbostock requested review from Fil and cinxmo November 28, 2023 03:27
Comment on lines +43 to +44
const missingFiles = difference(expectedFiles, actualFiles);
const unexpectedFiles = difference(actualFiles, expectedFiles);
Copy link
Member Author

Choose a reason for hiding this comment

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

Fixing inverted logic!

export async function rollupClient(clientPath = getClientPath(), {minify = false} = {}): Promise<string> {
const bundle = await rollup({input: clientPath, external: ["./runtime.js", /^https:/]});
try {
const output = await bundle.generate({format: "es", plugins: minify ? [(terser as any)()] : []});
Copy link
Member Author

Choose a reason for hiding this comment

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

The terser as any here fixes a TypeScript error I don’t understand:

This expression is not callable.
  Type 'typeof import("/Users/mbostock/Development/observablehq-multi/cli/node_modules/@rollup/plugin-terser/types/index")' has no call signatures.ts(2349)

It seems like TypeScript isn’t resolving the types correctly. 🤷

@mbostock mbostock force-pushed the mbostock/rollup-client branch from 832b9a1 to 6ecd8c9 Compare November 28, 2023 03:39
@mbostock mbostock enabled auto-merge (squash) November 28, 2023 03:42
Copy link
Contributor

@Fil Fil left a comment

Choose a reason for hiding this comment

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

nice!

@mbostock mbostock merged commit 480776f into main Nov 28, 2023
@mbostock mbostock deleted the mbostock/rollup-client branch November 28, 2023 07:32
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Don’t copy public/database.js is to dist if unused Bundle and minify client.js during build

2 participants