Skip to content
Open
Show file tree
Hide file tree
Changes from all 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
6 changes: 6 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -218,6 +218,12 @@ Console output
| tailwindConfig | `Config` | {} | Set your tailwind config here |
| postCSSPlugins | `AcceptedPlugin[]` | [] | Array of acceptable postcss plugins |

### ConverterOptions(options?)

| Option | Type | Default | Description |
| ------------------------- | --------- | ------- | -------------------------------------------------------------------- |
| skipAddingTailwindClasses | `boolean` | `false` | Defines whether to skip adding tailwind classes to the converted CSS |

[build-img]: https://github.com/jackardios/css-to-tailwindcss/actions/workflows/release.yml/badge.svg
[build-url]: https://github.com/jackardios/css-to-tailwindcss/actions/workflows/release.yml
[downloads-img]: https://img.shields.io/npm/dt/css-to-tailwindcss
Expand Down
29 changes: 18 additions & 11 deletions src/TailwindConverter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,10 @@ export interface ResolvedTailwindConverterConfig
mapping: ConverterMapping;
}

export interface ConverterOptions {
skipAddingTailwindClasses?: boolean;
}

export const DEFAULT_CONVERTER_CONFIG: Omit<
TailwindConverterConfig,
'tailwindConfig'
Expand Down Expand Up @@ -76,7 +80,7 @@ export class TailwindConverter {
};
}

async convertCSS(css: string) {
async convertCSS(css: string, options?: ConverterOptions) {
const nodesManager = new TailwindNodesManager();
const parsed = await postcss(this.config.postCSSPlugins).process(css, {
parser: postcssSafeParser,
Expand All @@ -90,16 +94,19 @@ export class TailwindConverter {
});

const nodes = nodesManager.getNodes();
nodes.forEach(node => {
if (node.tailwindClasses.length) {
node.rule.prepend(
new AtRule({
name: 'apply',
params: node.tailwindClasses.join(' '),
})
);
}
});

if (!options?.skipAddingTailwindClasses) {
nodes.forEach(node => {
if (node.tailwindClasses.length) {
node.rule.prepend(
new AtRule({
name: 'apply',
params: node.tailwindClasses.join(' '),
})
);
}
});
}

this.cleanRaws(parsed.root);

Expand Down
Loading