Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: add processor css modules support #174

Merged
merged 7 commits into from
Dec 27, 2024

Conversation

marcalexiei
Copy link
Collaborator

@marcalexiei marcalexiei commented Dec 10, 2024

Close #173

Add support of CSS modules via processor function.

When user return a cssModules property from processor output it will be used as default export from the css file.

Example

sass({
  // ...pluginOptions,
  processor: async (styles, id) => {
    let cssModules = {};
    const postcssProcessResult = await postcss([
      postcssModules({
        getJSON: (_, json) => {
          if (json) cssModules = json;
        },
      }),
    ]).process(styles, {
      from: id,
    });

    return { css: postcssProcessResult.css, cssModules };
  },
});

TODOs

  • insert unit test
  • test along other named exports
  • add documentation

@marcalexiei marcalexiei marked this pull request as draft December 10, 2024 18:27
@marcalexiei marcalexiei force-pushed the processor-css-modules branch from 87400da to d737c5d Compare December 10, 2024 18:30
@marcalexiei marcalexiei marked this pull request as ready for review December 11, 2024 10:34
@marcalexiei marcalexiei requested a review from elycruz December 11, 2024 10:34
Copy link
Owner

@elycruz elycruz left a comment

Choose a reason for hiding this comment

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

Good work ! Left one comment:

src/utils/processRenderResponse.ts Outdated Show resolved Hide resolved
@marcalexiei marcalexiei requested a review from elycruz December 21, 2024 10:45
@elycruz elycruz merged commit cd748b2 into elycruz:main Dec 27, 2024
8 checks passed
@marcalexiei marcalexiei deleted the processor-css-modules branch December 27, 2024 08:15
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.

Question / feature request: use processor to generate CSS modules
2 participants