Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Browser build for client #499

Open
curran opened this issue Jul 22, 2021 · 11 comments
Open

Browser build for client #499

curran opened this issue Jul 22, 2021 · 11 comments

Comments

@curran
Copy link
Contributor

curran commented Jul 22, 2021

I'm experimenting with using dependencies from a CDN, and it would be interesting to expose sharedb/lib/client in a browser build with a browser global. That way it would be possible to load the ShareDB client from a CDN, rather than include it in the project bundle.

Would this be of interest to anyone else?

@curran
Copy link
Contributor Author

curran commented Jul 22, 2021

FWIW it comes to about 86KB minified, using a Rollup build with Node polyfills

In the ShareDB examples with Browserify, it comes to about 98KB minified.

cd examples/counter/static/dist
uglifyjs --compress --mangle -- bundle.js > min.js

@curran
Copy link
Contributor Author

curran commented Jul 22, 2021

To be clear, what I'm proposing is that we introduce a new file in the NPM package for ShareDB (that's not tracked in Git), which is a Rollup-based UMD build of sharedb/lib/client.

@curran
Copy link
Contributor Author

curran commented Jul 22, 2021

Managed to get the browser build down to 68KB using Closure compiler.

@curran
Copy link
Contributor Author

curran commented Jul 22, 2021

It might make sense for this to even be a downstream package from ShareDB. That would satisfy the need as well.

@curran
Copy link
Contributor Author

curran commented Jul 24, 2021

So I got this working. Thinking to publish this on NPM as sharedb-client-browser.

https://github.com/curran/sharedb-client-browser

Thoughts?

@curran
Copy link
Contributor Author

curran commented Jul 24, 2021

Got the bundle down to 65kB using a more up to date Node polyfill library.

@curran
Copy link
Contributor Author

curran commented Jul 24, 2021

@curran
Copy link
Contributor Author

curran commented Jul 24, 2021

Turns out such a small bundle was a pipe dream. Closure compiler renamed fields, which broke ShareDB. After switching to "simple" compilation mode, everything actually works and the bundle is 83.6 kB.

@curran
Copy link
Contributor Author

curran commented Jul 24, 2021

Closing as this is done, albeit externally to mainline ShareDB.

If there is any interest in including the browser build in mainline ShareDB feel free to reopen!

@curran
Copy link
Contributor Author

curran commented Mar 3, 2023

Reopening as this is not really a solved problem.

ShareDB does not provide a build in its NPM distribution that is compatible with widely used tools like Vite, as demonstrated in #598

Ideally ShareDB would provide a build for the client entrypoint that is compatible with Vite and other build systems that do not have built-in support for Node polyfills.

Proposal

Introduce a new asset published to NPM that is a pre-built bundle of the client-side only.

For consumers of ShareDB, instead of saying

import sharedb from 'sharedb/lib/client'

we could say

import sharedb from 'sharedb/lib/client-browser.js'

To produce client-browser.js, the prepublish step of ShareDB itself could include a step that runs sharedb/lib/client through browserify, much like the examples do, which would include the appropriate Node polyfills.

Thoughts?

@curran
Copy link
Contributor Author

curran commented Mar 4, 2023

Upgraded https://github.com/vizhub-core/sharedb-client-browser to use Browserify and the latest ShareDB version.

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

No branches or pull requests

1 participant