Skip to content

Commit

Permalink
fix: should not compile the standard classes when using prefix (#534)
Browse files Browse the repository at this point in the history
  • Loading branch information
aki77 committed Oct 27, 2021
1 parent 37faf6c commit 0910829
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 2 deletions.
1 change: 1 addition & 0 deletions src/lib/extract.ts
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ export default function extract(
addComment = false,
prefix?: string,
): Style | Style[] | undefined {
if (prefix && !className.startsWith(prefix)) return;

// handle static base utilities
if (!prefix && className in staticUtilities) return generateStaticStyle(processor, className, addComment);
Expand Down
6 changes: 4 additions & 2 deletions test/processor/config.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import { Processor } from '../../src/lib';
import { twExclude } from '../../src/config';
import { CSSParser } from '../../src/utils/parser';
import type { colorObject } from '../../src/interfaces';
import aspectRatio from '../../src/plugin/aspect-ratio';

const configPath = resolve('./test/assets/windi.config.js');
const userConfig = require(configPath);
Expand Down Expand Up @@ -116,10 +117,11 @@ describe('Config', () => {

it('does not generate non-prefixed classes when using prefix', () => {
const processor = new Processor({ prefix: 'windi-' });
const classes = 'items-center justify-center flex-wrap block flex windi-block';
processor.loadPlugin(aspectRatio);
const classes = 'items-center justify-center flex-wrap block flex windi-block windi-py-3 py-3 container aspect-none';
// it should not compile the standard classes (items-center, justify-center) because they are not prefixed
expect(processor.interpret(classes).styleSheet.build()).toBe(
'.windi-block {\n display: block;\n}'
'.windi-block {\n display: block;\n}\n.windi-py-3 {\n padding-top: 0.75rem;\n padding-bottom: 0.75rem;\n}'
);
});

Expand Down

0 comments on commit 0910829

Please sign in to comment.