Skip to content

Map CSS to ESM output - #16

Merged
remcohaszing merged 4 commits into
mainfrom
esm
Nov 26, 2026
Merged

remcohaszing merged 4 commits into
mainfrom
esm

Conversation

@remcohaszing

Copy link
Copy Markdown
Owner

Mapping to CJS doesn’t work in all situations. This change maps CSS content to ESM instead. This means we need to expose both named and a default export.

This also opens up the door for adding options for disabling default or named exports later.

The local name shows up in hover information. I don’t think $ + index looks that great. IMO it’s fine for an initial iteration, but we can probably improve on this.

image

Mapping to CJS doesn’t work in all situations. This change maps CSS
content to ESM instead. This means we need to expose both named and a
default export.

This also opens up the door for adding options for disabling default
or named exports later.
@remcohaszing
remcohaszing requested a review from mrmckeb November 20, 2026 11:37
@changeset-bot

changeset-bot Bot commented Nov 20, 2026 •

Copy link
Copy Markdown

⚠️ No Changeset found

Latest commit: cb60aaf

Merging this PR will not cause a version bump for any packages. If these changes should not result in a new version, you're good to go. If these changes should result in a version bump, you need to add a changeset.

This PR includes no changesets

When changesets are added to this PR, you'll see the packages that this PR includes changesets for and the associated semver types

Click here to learn what changesets are, and how to add one.

Click here if you're a maintainer who wants to add a changeset to this PR

@github-actions

github-actions Bot commented Nov 20, 2026 •

Copy link
Copy Markdown
Contributor

⚠️ No Changeset found

Latest commit: cb60aaf

Merging this PR will not cause a version bump for any packages. If these changes should not result in a new version, you're good to go. If these changes should result in a version bump, you need to add a changeset.

This PR includes no changesets

When changesets are added to this PR, you'll see the packages that this PR includes changesets for and the associated semver types

Click here to learn what changesets are, and how to add one.

Click here if you're a maintainer who wants to add a changeset to this PR

@mrmckeb mrmckeb left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This looks great, thanks! The only other note is that class names like
.styles, .$0, and .default create duplicates.

I'm happy to pick that up in a separate PR too!

if (!adapter.preprocess) {
return {
extension: '.cts',
extension: '.ts',

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm can pick this up in a follow-up, but it sounds like we also need a pathway for users that are in a CJS environment with "module": "nodenext", where we would export a .cts file with compatible output?

For this PR, happy to make ESM the priority.

Copy link
Copy Markdown
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is related to microsoft/TypeScript#64182 (comment).

Realistically though, I think this won’t be a practical issue. I think this will typically be used with a bundler, meaning users should set module to preserve or esnext.

CSS modules doesn’t define an export format, so we could support CJS. For content mappers for other languages, this might not even be possible. For example, MDX even allows users to write ESM syntax.

I think we should wait with adding back CJS support for now and see if anyone asks for it first.

@remcohaszing
remcohaszing merged commit 8b05f65 into main Nov 26, 2026
9 checks passed
@remcohaszing
remcohaszing deleted the esm branch November 26, 2026 13:09
remcohaszing added a commit that referenced this pull request Nov 26, 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