Ship ESM and CommonJS builds so packages are importable by bundlers - #186
Merged
Merged
Conversation
Copilot
AI
changed the title
[WIP] Fix npm build to support module exports for bundlers
Ship ESM and CommonJS builds so packages are importable by bundlers
Sep 23, 2026
There was a problem hiding this comment.
Copilot review overview
🟡 Changes recommended
The review identified packaging/build issues that can mislead consumers (Node engine constraints) and potentially break sourcemap correctness for renamed CSS outputs.
Get a fresh assessment by requesting another Copilot review.
Review effort: Lite
Findings: 1
Open (3)
What changed in this PR
This PR updates MatGUI’s build and package metadata so the published npm artifacts are importable by bundlers and Node consumers (ESM/CJS), while preserving the existing browser-global IIFE distribution for <script> usage—addressing issue #185.
Changes:
- Extend the esbuild pipeline to emit ESM (
.mjs), CJS (.cjs), and IIFE (.min.js) bundles per package while keeping a single canonical CSS output. - Update each package’s
package.jsonto exposemain/module/unpkg/jsdelivrand a conditionalexportsmap for import/require/types/default (plus CSS/build subpaths where relevant). - Add a regression unit test that validates the packed tarball’s structure and verifies ESM/CJS resolution and a Vite build consumer.
| File | Description |
|---|---|
esbuild.config.js |
Builds per-package ESM/CJS/IIFE outputs and manages a single canonical CSS artifact. |
packages/yasgui/package.json |
Adds main/module/exports/CDN fields so bundlers and Node can resolve the package correctly. |
packages/yasqe/package.json |
Adds main/module/exports/CDN fields so bundlers and Node can resolve the package correctly. |
packages/yasr/package.json |
Adds main/module/exports/CDN fields so bundlers and Node can resolve the package correctly. |
packages/utils/package.json |
Adds main/module/exports/CDN fields so bundlers and Node can resolve the package correctly. |
test/unit/package-consumption-test.ts |
Regression test that exercises npm pack output and validates ESM/CJS resolution and Vite bundling. |
docs/developer-guide.md |
Updates CommonJS usage to access the default export via .default. |
.changeset/esm-module-exports.md |
Records a minor release note describing the new ESM/CJS publishing behavior. |
💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.
Refactor CSS extraction logic to handle renaming and sourcemaps more robustly. Co-authored-by: Copilot Autofix powered by AI <175728472+Copilot@users.noreply.github.com>
Co-authored-by: MathiasVDA <15101339+MathiasVDA@users.noreply.github.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.


Packages only shipped an IIFE (browser-global) bundle, so
import Yasgui from '@matdata/yasgui'failed in Vite/webpack/esbuild despite the docs advertising it.Changes
esbuild.config.js— Each package now emits three JS bundles instead of one: ESM (*.mjs), CommonJS (*.cjs), and the existing browser-global IIFE (*.min.js). A single canonical*.min.cssis retained (all three JS bundles import identical styles; extractedextractCss/removeExtraCsshelpers handle this).packages/*/package.json(all 4) — Addedmain(CJS),module(ESM),unpkg/jsdelivr(global), and a conditionalexportsmap withimport/require/types/defaultplus CSS and./build/*subpaths..mjs/.cjsrather than.esm.js/.cjs.js: files underbuild/inherit the root"type": "module", making bare.jsambiguous to Node. Explicit extensions guarantee correct format resolution in every consumer.require('@matdata/yasgui').default(esbuild places the default under.default); minor changeset added for all four packages.Existing
<script src=".../build/yasgui.min.js">global usage is preserved viaunpkg/jsdelivr.