Coder Social home page Coder Social logo

Comments (3)

justjake avatar justjake commented on May 29, 2024

Yes, this is something I’d like to address. I made an attempt to produce a module-native build about a year ago, but ran into substantial issues with Typescript’s build modes at the time. I think the situation has improved to the point that this may be easier to do without involving a bundler like ESBuild or Rollup. Bundlers are fine but I’d like to avoid the extra complexity.

from quickjs-emscripten.

justjake avatar justjake commented on May 29, 2024

Update: Bundlephobia reports the library size as 10kb now 🎉 https://bundlephobia.com/package/[email protected].

from quickjs-emscripten.

niedzielski avatar niedzielski commented on May 29, 2024

Thank you for writing this super cool library! I've just started exploring it in detail and found a couple notes that seem relevant to this issue that I wanted to share.

  1. esm.sh builds are pre-bundled. I don't think these can be easily be split or tree-shaken. Here's an example (ignore the giant blob of Deno built-ins, npx source-map-explorer public/dist/*.js): Screenshot from 2023-03-08 08-56-40
  2. The NPM install seems to require a lot of manual externalization for unused imports. Here's an example from esbuild with the defaults: Screenshot from 2023-03-08 08-57-45 and with externals: Screenshot from 2023-03-08 09-02-15. The minified gzipped size of the latter is about a half-megabyte (cat dist/*.js|gzip --best|wc -c).

external config for the latter:

/** @type {esbuild.BuildOptions} */
const options = {
  bundle: true,
  entryPoints: [input],
  external: [
    '*.WASM_DEBUG_ASYNC.js',
    '*.WASM_DEBUG_SYNC.js',
    '*.WASM_RELEASE_SYNC.js',
    '*.WASM_DEBUG_ASYNCIFY.js',
    'fs',
    'path'
  ],
  sourcemap: 'linked',
  format: 'esm',
  logLevel: 'warning',
  outfile: output,
  platform: 'browser',
  minify: true,
  treeShaking: true
}

I think it'd be really handy to split the entrypoints exposed by the library so that users can import just the one relevant to their project. For power users, it'd be awesome to expose the .wasm blobs instead of inlining them as base64. I think this would look like an entrypoint with just the JavaScript bindings and an API that accepted a Wasm URL (coincidentally, esbuild is also available in Wasm and takes this approach--example).

Thank you again for this really library! I just wanted to share these notes before I lost them!

from quickjs-emscripten.

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.