Hi! I’m trying to use Bokehjs in a web app which uses webpack as a bundler, it actually works but I get quite large resulting js bundle of size 3MB. I’m not very proficient at writing webpack configs, but I wonder if it is actually a good/supported way to include bokeh in your app at all? I searched documentation and examples but looks like this is not very popular way to use bokeh (at least).
I’m importing bokeh like this:
import * as Bokeh from '@bokeh/bokehjs'
const plt = Bokeh.Plotting
const np = Bokeh.LinAlg
const n = 100;
const x = np.linspace(0, 20, n);
const y = x.map(x => Math.sin(x));
const p = plt.figure({ height: 300 });
p.line(x, y);
plt.show(p, "#root");
That report shows that you are including all the optional modules for tables, widgets, and webgl support. Are you actually using those features? If so, then there’s not much to do on the Bokeh side of things.
Seems like I figured it out myself. Not sure if this is the best way, but that is what I ended up with:
import { figure, show } from "@bokeh/bokehjs/build/js/lib/api/plotting"
import { linspace } from "@bokeh/bokehjs/build/js/lib/api/linalg"
const n = 100;
const x = linspace(0, 20, n);
const y = x.map(x => Math.sin(x));
const p = figure({ height: 300 });
p.line(x, y);
show(p, "#root");
So, now main.bundle.js in only 673 KB, which is even less than 800 KB of bokeh-2.4.2.min.js. Other modules are extracted as separate bundles, which could be loaded on demand. They have not very readable names, but it is easy to guess what is inside from the picture: