GithubHelp home page GithubHelp logo

Bundle size optimisations? about biota HOT 8 OPEN

gahabeen avatar gahabeen commented on June 3, 2024
Bundle size optimisations?

from biota.

Comments (8)

gahabeen avatar gahabeen commented on June 3, 2024 1

Hey,

I'm all for it πŸ™Œ
Size matters and it should be as small as possible. Biota is still new and clearly needs optimization.

Biota is build to be ran in any environment: client or server. So it should be able to fit in a CloudflareWorker too. Also, one nice thing about biota is that everything can be loaded in fauna (methods are individual User-Defined Functions too) so you - potentially - would only need to be calling fauna's endpoint for User-Defined Functions.

It'ld lovely of you to have a look and see what's possible for tree-shaking and size optimization in general.

Thanks!
P.S: Be careful, project isn't production ready just yet πŸ˜‰

from biota.

vinaypuppal avatar vinaypuppal commented on June 3, 2024 1

Hi, I did not get chance to look in to the existing config yet. I am planning to check it this weekend and I let you know.

from biota.

gahabeen avatar gahabeen commented on June 3, 2024 1

I'll have a look at those. Seems promising :)

from biota.

gahabeen avatar gahabeen commented on June 3, 2024 1

I'm splitting biota in quite a few libraries. Like @biota/schema, @biota/builder, @biota/factory, @biota/api, @biota/auth, etc.

I'm reorganizing in a composable way just so it becomes tiny (and even more readable).
Btw, I'm using microbundle as following your recommendations ;)

Just the looking at the number of characters, I reduced it by 8 times :)

I'll let you know once it's up!
(Disputing the @biota organization on npmjs right now, and still have some work before release anyway)

from biota.

gahabeen avatar gahabeen commented on June 3, 2024

I've set up a webpack config instead (https://github.com/gahabeen/biota/blob/revamp/webpack.config.js).
It's still way too big because of the number of files and contents.

I think I'll write a second super-light library to use biota with the hosted code on fauna (in user-defined functions). It should be easy as well and weight nothing.

Let me know what you think @vinaypuppal.
I'll also need to refactor some code at some point anyway too.

from biota.

vinaypuppal avatar vinaypuppal commented on June 3, 2024

Hi, @gahabeen Sorry for replying late was busy with work

  1. Rather than using Webpack, we should use Rollup as this is library. A quote from this article

If your codebase is ES2015 modules and you’re making something to be used by other people, you probably want Rollup.

  1. As mentioned in the article I would suggest changing tsconfig to
-    "target": "es5",
-    "lib": ["es2015", "dom"],
-    "module": "commonjs",
+    "target": "esnext",
+    "lib": ["esnext", "dom"],
+    "module": "ESNext",

So TS -> ESNext will be built and then we can use microbundle or our own rollup config to generate commonjs and umd bundle.

Note: As mentioned in the article we should mention the module filed in package.json which should point to ES Modules version of our lib, so bundlers used by our library users like Webpack can implement tree-shaking.

  "main": "dist/foo.js",           // output path for CommonJS/Node
  "module": "dist/foo.module.js",  // output path for JS Modules
  "unpkg": "dist/foo.umd.js",      // optional, for unpkg.com

I tried to integrate microbundle in the revamp branch but I am getting a lot of TS errors so I did not continue. Once you are done with the API changes lets experiment with microbundle or our own rollup config and see bundle size.

from biota.

vinaypuppal avatar vinaypuppal commented on June 3, 2024

One more indicator for tree-shaking to work is we need to add is sideEffects field in package.json
More info about it here

from biota.

vinaypuppal avatar vinaypuppal commented on June 3, 2024

Awesome!

Waiting for the release.

from biota.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    πŸ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. πŸ“ŠπŸ“ˆπŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❀️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.