mizdra / happy-css-modules

Typed, definition jumpable CSS Modules. Moreover, easy!
MIT License
213 stars 5 forks source link

Compatibility with `css-loader@7` #255

Open mizdra opened 1 month ago

mizdra commented 1 month ago

Background

In css-loader@7, namedExport now defaults to true (I'm not sure of the motivation behind this change.).

So css-loader@7 forces you to import CSS Modules files as follows:

import * as styles from './foo.module.css';

On the other hand, happy-css-modules generates .d.ts with default export.

https://github.com/mizdra/happy-css-modules/blob/613391616b299a6fe2f10598a8da85e5a1b0e728/packages/example/01-basic/1.css.d.ts#L1-L21

Therefore happy-css-modules forces you to import CSS Modules files as follows:

import styles from './foo.module.css';

This causes compatibility problems.

Solution

I don't know how to solve this.

happy-css-modules previously supported --namedExport option. However, it was removed due to problems with definition jumps not working.

I think it would be best to bring back this option and make definition jumps work as well. However, I am not sure if that is possible.

Workaround

Please set the namedExport option to false in css-loader.