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

[next] Wrap all generated CSS with a cascade layer (WIP) #226

Merged
merged 3 commits into from
Sep 11, 2024
Merged
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 14 additions & 2 deletions packages/pigment-css-unplugin/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,6 @@ import {
} from '@pigment-css/react/utils';
import type { ResolvePluginInstance } from 'webpack';
import { styledEngineMockup } from '@pigment-css/react/internal';

import { handleUrlReplacement, type AsyncResolver } from './utils';

type NextMeta = {
Expand Down Expand Up @@ -284,6 +283,19 @@ export const plugin = createUnplugin<PigmentOptions, true>((options) => {
}

let { cssText } = result;

const slug = slugify(cssText);
Copy link
Contributor

@brijeshb42 brijeshb42 Sep 11, 2024

Choose a reason for hiding this comment

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

Can you move the whole thing at the end of the if (isNext) check at line https://github.com/mui/pigment-css/blob/master/packages/pigment-css-unplugin/src/index.ts#L301

since we mainly want to do this for next.js and not webpack (unless someone reports it for webpack as well).


// Valid names must start with a underscore or letter.
const layerName = `_${slug}`;

// TODO: Do this in a way that keeps the source map correct
cssText = `
@layer pigment.${layerName} {
${cssText}
}
`;

if (isNext && !outputCss) {
return {
code: result.code,
Expand Down Expand Up @@ -324,7 +336,7 @@ export const plugin = createUnplugin<PigmentOptions, true>((options) => {
}

const rootPath = process.cwd();
const slug = slugify(cssText);

const cssFilename = path
.normalize(`${id.replace(/\.[jt]sx?$/, '')}-${slug}.pigment.css`)
.replace(/\\/g, path.posix.sep);
Expand Down
Loading