Client-Side Workaround for Importing Legacy Scripts as ES Modules

Frontend developers often juggle libraries with different distribution formats — some expose globals, others rely on npm or module loaders, and many assume ES6 import syntax. Building for all these scenarios is tedious, but a recent post by Lea offers a practical approach for pulling non-ESM libraries into an ES module environment anyway.

window.module = {};
import("https://cdn.jsdelivr.net/gh/reworkcss/css@latest/lib/parse/index.js").then(_ => {
  console.log(module.exports);
});

For cases needing extra safety, the post suggests wrapping the process in a small abstraction function. It’s a simple client-side solution that sidesteps build tools entirely, and the article includes another clever trick worth checking out via the direct link.