ReviewOS

stacks/bun-plugin-unocss

React/JS support?

#6
Open jaredly opened this 9 days ago ·
9 days ago

Clear and concise description of the problem

It looks like this plugin only handles processing HTML files; I use bun to compile my react/tsx files, and am interested in trying out unocss.

Suggested solution

How hard would it be to add that functionality?

Alternative

No response

Additional context

No response

Validations

9 days ago

Here's what I ended up doing

import type { UserConfig } from '@unocss/core';
import type { BunPlugin } from 'bun';
import { loadConfig } from '@unocss/config';
import { createGenerator } from '@unocss/core';

const makeCss = async (js: string) => {
    const found: string[] = [];
    js.replace(/className:\s*"([^"]+)"/, (ok, what) => {
        found.push(...what.split(' '));
        return '';
    });
    const generator = await createGenerator((await loadConfig()).config);
    return generator.generate(found);
};

Sign in to comment on this issue.