Skip to content

Remove ESM bundles and point to source directly - #739

Merged
LeaVerou merged 2 commits into
mainfrom
claude/epic-brown-7mvg9r
Jun 19, 2026
Merged

LeaVerou merged 2 commits into
mainfrom
claude/epic-brown-7mvg9r

Conversation

@LeaVerou

@LeaVerou LeaVerou commented Jun 15, 2026 •

Copy link
Copy Markdown
Member

Closes #662

This PR removes the pre-built ESM bundles from the distribution and updates all references to point directly to the source files instead.

Summary

The ESM bundles (dist/color.js and dist/color-fn.js) are being removed since ESM consumers can import directly from the source via the package's exports field. This simplifies the build process and reduces maintenance overhead by eliminating the need to keep bundled ESM files in sync with source changes.

It also fixes the dual-instance problem behind color-js/elements#192: when the main . export resolved to a separate bundled copy, consumers importing src/ got a different Color (with its own color-space registry) than those importing the package root, so custom spaces registered through one didn't appear in the other.

Key Changes

  • Package.json: Updated the . ESM exports and the module field to point to src/index.js instead of the bundled dist/color.js, matching how ./fn and ./spaces already export src/.
  • Rollup config: Removed ESM bundle configurations for both main and function-based builds, keeping only IIFE (global) and CommonJS formats.
  • Documentation & examples: Updated import statements in the README, the get page, and the website's own colors.js asset to reference src/index.js directly.

Implementation Details

  • ESM consumers now import directly from source, which is already supported via the package's exports configuration.
  • CommonJS users continue to use the bundled dist/color.cjs (and dist/color-fn.cjs for ./fn).
  • Classic <script> users continue to use the global IIFE build (dist/color.global.js), and the .legacy CommonJS/global builds are unaffected.

@netlify

netlify Bot commented Jun 15, 2026 •

Copy link
Copy Markdown

βœ… Deploy Preview for colorjs ready!

Name Link
πŸ”¨ Latest commit 33ad2dc
πŸ” Latest deploy log https://app.netlify.com/projects/colorjs/deploys/6a353a9a27abf3000820e1a8
😎 Deploy Preview https://deploy-preview-739--colorjs.netlify.app
πŸ“± Preview on mobile
Toggle QR Code...

QR Code

Use your smartphone camera to open QR code link.
πŸ€– Make changes Run an agent on this branch

To edit notification comments on pull requests, go to your Netlify project configuration.

The main "." export's ESM entry pointed to the bundled ./dist/color.js,
while ./fn and ./spaces already exported src/ directly. This left the OOP
entry point as the only ESM export still resolving to a separate bundled
copy of the library, with its own color-space registry distinct from
anyone importing src/ β€” the cause of color-js/elements#192, where custom
spaces registered via one instance don't appear in the other.

Point the ESM import (and the "module" field) at ./src/index.js so npm
consumers get a single instance. CJS continues to use the dist bundle via
"require", and the dist bundles are still built for CDN/global usage.

Closes #662
@LeaVerou
LeaVerou force-pushed the claude/epic-brown-7mvg9r branch 2 times, most recently from 2a2ddc5 to 14450a1 Compare June 19, 2026 11:59
Comment thread README.md Resolved
@LeaVerou
LeaVerou force-pushed the claude/epic-brown-7mvg9r branch from 0b14b67 to 14450a1 Compare June 19, 2026 12:25
With the package's ESM exports pointing at src/ directly, the bundled ESM
outputs (dist/color.js, dist/color-fn.js, their .min and .legacy variants)
are no longer consumed by anything. Drop them from the Rollup config; only
the CommonJS bundles (for require) and the global IIFE build (for classic
<script> use) still need bundling.

Repoint the few remaining references at src/: the website's own colors.js
asset and the CDN import examples in the README and get page now use
https://colorjs.io/src/index.js, matching how src modules are already
documented for partial imports.
@LeaVerou
LeaVerou force-pushed the claude/epic-brown-7mvg9r branch from 14450a1 to 33ad2dc Compare June 19, 2026 12:48
@LeaVerou
LeaVerou marked this pull request as ready for review June 19, 2026 12:58
@LeaVerou
LeaVerou merged commit 58bd099 into main Jun 19, 2026
5 checks passed
@LeaVerou
LeaVerou deleted the claude/epic-brown-7mvg9r branch June 19, 2026 15:32
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.

Do we need dist for ESM?

2 participants