activeguild / vite-plugin-sass-dts

This is a plugin that automatically creates a type file when using the CSS module type-safely.
MIT License
120 stars 19 forks source link

Empty ruleset skips adding class to `.d.ts` file #73

Closed tommy-mitchell closed 1 year ago

tommy-mitchell commented 1 year ago

I'm using a script that generates boilerplate for a new React component that creates an empty ruleset for its associated class in a scss module file:

// Foo.tsx
import styles from './Foo.module.scss';

function Foo() {
  return <div className={styles.foo}></div>;
}
// Foo.module.scss
.foo {
  @debug 'no styles added'; // included so Prettier doesn't complain
}

But when this plugin creates Foo.module.scss.d.ts, it ignores the "empty" .foo class:

declare const classNames: { };
export = classNames;

I'd make a PR, but I couldn't find in the code where this was being filtered out.

tommy-mitchell commented 1 year ago

As it turns out, the issue is that SCSS itself doesn’t emit empty rules. Adding a CSS comment does the trick:

.Foo {
  @debug “no styles added”;
  /* no styles added */
}