This PR adds hybrid module generation so we have specific builds.
Changes in detail
Runtime specific esbuilds commands
We now have three invocations of esbuild, which generate:
a browser optimised iife version for using when you have a browser and no tooling for managing code bundles
a ES imports based version this is likely the most popular version, and is designed for broad, modern API support
a CommonJS based version aimed at node 14 upwards, that uses APIs that only NodeJS has. This is targeted at serverside use cases like you see in sitespeed.io, and doe not rely on fetch, but uses the existing HTTP libraries native to node before node 18.
hybrid module entry points
For this to be possible, we need different code entry points
For nodejs
Some software consuming co2.js uses it in server side nodejs projects like sitespeed.io. which use commonjs variants. To support this, the esbuild.nodejs runs a build to generates a CommonJS compatible build and places it in ./dist/cjs/index-node.js.
For modern ES module capable clients
Most of other software likely would consume co2.js as ES modules (referred to as esm). The entry point for esm code is in dist/esm/index.js. This is likely the more common approach going forward.
For use in browsers when you don't want to faff around
Finally, for folks who do not want to rely on third party hosted services or fiddly build steps, we have a single file version presented as an immediately invoked function express.
This can be run locally with the npm run serve command if you check out this repo, as a demo
This PR adds hybrid module generation so we have specific builds.
Changes in detail
Runtime specific esbuilds commands
We now have three invocations of esbuild, which generate:
hybrid module entry points
For this to be possible, we need different code entry points
For nodejs
Some software consuming co2.js uses it in server side nodejs projects like sitespeed.io. which use commonjs variants. To support this, the
esbuild.nodejs
runs a build to generates a CommonJS compatible build and places it in./dist/cjs/index-node.js
.For modern ES module capable clients
Most of other software likely would consume co2.js as ES modules (referred to as
esm
). The entry point foresm
code is indist/esm/index.js
. This is likely the more common approach going forward.These build is what is consumed by Skypack in this codepen and Observable in this demo notebook
For use in browsers when you don't want to faff around
Finally, for folks who do not want to rely on third party hosted services or fiddly build steps, we have a single file version presented as an immediately invoked function express.
This can be run locally with the
npm run serve
command if you check out this repo, as a demo