Open curran opened 3 years ago
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
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
.
Managed to get the browser build down to 68KB using Closure compiler.
It might make sense for this to even be a downstream package from ShareDB. That would satisfy the need as well.
So I got this working. Thinking to publish this on NPM as sharedb-client-browser
.
https://github.com/curran/sharedb-client-browser
Thoughts?
Got the bundle down to 65kB using a more up to date Node polyfill library.
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.
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!
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 https://github.com/share/sharedb/pull/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.
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?
Upgraded https://github.com/vizhub-core/sharedb-client-browser to use Browserify and the latest ShareDB version.
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?