Skip to content

Publish library as ESM#232

Merged
cburgmer merged 1 commit intocburgmer:masterfrom
bernardobelchior:bernardobelchior/modernize-codebase
Feb 3, 2026
Merged

Publish library as ESM#232
cburgmer merged 1 commit intocburgmer:masterfrom
bernardobelchior:bernardobelchior/modernize-codebase

Conversation

@bernardobelchior
Copy link
Collaborator

Publish library as ESM. This PR adds Rollup as a bundler which runs build/rasterizeHTML.concat.js through a transpile step that outputs ESM and UMD (to ensure backward compatibility).

The UMD export is available at dist/rasterizeHTML.js. You can see that it contains code at the top to check for module.exports (CJS), define (for AMD) and ultimately sets window.rasterizeHTML if none of the first conditions pass.

The ESM bundle is available at dist/rasterizeHTML.mjs.

This isn't a breaking change as I've intentionally left the output paths the same. dist/rasterizeHTML.js is still UMD as before. The only addition is that we now have a dist/rasterizeHTML.mjs which is an ESM build.

I've also intentionally left the minified bundles (and added one for ESM). We can remove this when we do breaking changes as it isn't necessary. For users who want to minify, it makes more sense to do it when bundling the application that includes this library instead of including the minified library.

To test this, I've created this branch that contains a Webpack application to test ESM, UMD and CJS. Importing ESM directly (e.g., using <script type="module"> plus import maps) doesn't work because the dependencies of rasterizeHTML aren't published as ESM. You can test this method by opening this index.html (doesn't require a webpack build, unlike the other options).

Let me know if you have any questions. I'm diffed the current and new output and everything seems fine, but I'm not an expert in JS module systems, so something might be wrong.

@bernardobelchior bernardobelchior requested review from cburgmer and removed request for cburgmer January 30, 2026 10:23
@bernardobelchior bernardobelchior marked this pull request as draft January 30, 2026 12:17
@bernardobelchior bernardobelchior marked this pull request as ready for review January 30, 2026 17:03
@cburgmer
Copy link
Owner

cburgmer commented Feb 3, 2026

This looks good! Thank you for the work.

./test/integrationTest.js is happy, so I trust the allinone bundle is still being correctly built.

@cburgmer cburgmer merged commit c1d530b into cburgmer:master Feb 3, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants