-
-
Notifications
You must be signed in to change notification settings - Fork 780
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
Attributify with Astro missing some styles in some cases #1584
Comments
an alternative way could be to use a transformers: [
{
name: 'uno-astro-patch',
enforce: 'pre',
idFilter: id => !!id.match(/\.astro$/),
async transform(code) {
const matches = [...code.original.matchAll(/\$\{\$\$(addAttribute|spreadAttributes)/g)]
if (!matches.length)
return
for (const match of matches) {
const start = match.index
code.overwrite(start, start + match[0].length, ` ${match[0]}`)
}
},
},
...
], |
I think @impcyber means a Vite transformer. This alternative is better and easier but will add an extra space to the final output. And we can add another transformer to remove the spaces if the spaces ever matter. EDIT: This still can potentially break other plugins which rely on the absence of spaces. But the chance is small. |
This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions. |
This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions. |
As a workaround you can use // https://astro.build/config
export default defineConfig({
integrations: [
Unocss({
extraContent: {
filesystem: ['src/**/*.astro']
},
presets: [presetUno(), presetAttributify()],
}),
],
}); |
This is a known problem and has been mentioned in #105 (comment). I'm opening a new issue here for further tracking it.
The case
The attributify extractor fails to generate style for
text-red-500
Reproduction: https://stackblitz.com/edit/withastro-astro-vkmvgi?file=src%2Fpages%2Findex.astro
Why
As I've mentioned:
What can we do
Option 1: pre-process the source before extracting
This is what I've done in astro-uno, but it's a bit hacky.
Option 2: make Astro allow UnoCSS to be applied earlier
This is not quite possible since the use case is rare. (And the Astro guys chose not to include official UnoCSS integration, didn't they?)
Option 3: add an option for custom extractors
We can add some APIs for creating custom extractors from existing ones and pass them to attributify. This is similar to option 1 but less hacky. Also, if we decide to support a new framework in the future but the existing extractors are not working well, we can create a new extractor to solve this.
Other options
...
Additional comments
This is the last fix
astro-uno
provides but is not included inunocss/astro
.astro-uno
can safely retire afterunocss/astro
provides this fix.EDIT 1: Related issue: #1734
The text was updated successfully, but these errors were encountered: