partridgejiang / Kekule.js

A Javascript cheminformatics toolkit.
http://partridgejiang.github.io/Kekule.js
MIT License
247 stars 61 forks source link

dynamic module loading improves module import size? #293

Open filoscoder opened 1 year ago

filoscoder commented 1 year ago

We are importing Kekule like below

Screenshot 2022-11-12 at 9 34 40 PM

The size is huge, we only need IO, Editor, and ChemWidget modules. There is any way of importing modules with improved bundle sizes?

Can you provide examples of dynamic module loading please?

partridgejiang commented 1 year ago

Hi @filoscoder, if only certain modules are needed, you can use the utils/jsMinifier/ to build a custom min js file including only those modules to reduce the file size. E.g.:

node utils/jsMinifier/run.js -m io,chemWidget -d my/dest/path

Then use the custom kekule.min.js (not kekule.js):

import { Kekule } from "path/kekule.min.js";

However, since the editor is the most complex widget in package and requires a lot of functions from other modules, the reduced size is quite limited in the method above (from 2.56MB to 2.15MB).

filoscoder commented 1 year ago

Hi @filoscoder, if only certain modules are needed, you can use the utils/jsMinifier/ to build a custom min js file including only those modules to reduce the file size. E.g.:

node utils/jsMinifier/run.js -m io,chemWidget -d my/dest/path

Then use the custom kekule.min.js (not kekule.js):

import { Kekule } from "path/kekule.min.js";

However, since the editor is the most complex widget in package and requires a lot of functions from other modules, the reduced size is quite limited in the method above (from 2.56MB to 2.15MB).

I'm not following where is utils/jsMinifier, is a helper inside Kekule? Anyways It seems pretty unnecessary to customize the build for such a tiny difference. Thanks a lot for testing it beforehand!

partridgejiang commented 1 year ago

The jsMinifier util is in the source code repo: https://github.com/partridgejiang/Kekule.js/tree/master/utils/jsMinifier , :).

filoscoder commented 1 year ago

The jsMinifier util is in the source code repo: https://github.com/partridgejiang/Kekule.js/tree/master/utils/jsMinifier , :).

niceee, thanks a lot 🤙🏼