Repository navigation
Map CSS to ESM output - #16
Conversation
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.
|
|
mrmckeb
left a comment
There was a problem hiding this comment.
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', |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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.
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.