Skip to content

Commit

Permalink
fix(svelte-scoped): @unocss/reset module resolution (#2644)
Browse files Browse the repository at this point in the history
  • Loading branch information
jacob-8 committed May 22, 2023
1 parent 83574b8 commit 153d158
Show file tree
Hide file tree
Showing 4 changed files with 8 additions and 3 deletions.
1 change: 1 addition & 0 deletions docs/guide/index.md
Expand Up @@ -103,6 +103,7 @@ UnoCSS comes with many integrations for various frameworks:
- [Vite](/integrations/vite)
- [Nuxt](/integrations/nuxt)
- [Astro](/integrations/astro)
- [Svelte Scoped](/integrations/svelte-scoped)
- [Webpack](/integrations/webpack)
- [CLI](/integrations/cli)
- [PostCSS](/integrations/postcss)
Expand Down
2 changes: 1 addition & 1 deletion docs/integrations/svelte-scoped.md
Expand Up @@ -366,7 +366,7 @@ Do to the nature of having a few necessary styles in a global stylesheet and eve
| [@unocss/preset-uno](https://unocss.dev/presets/uno), [@unocss/preset-mini](https://unocss.dev/presets/mini), [@unocss/preset-wind](https://unocss.dev/presets/wind), [@unocss/preset-icons](https://github.com/unocss/unocss/tree/main/packages/preset-icons), [@unocss/web-fonts](https://github.com/unocss/unocss/tree/main/packages/preset-icons) || These and all community plugins, e.g. [unocss-preset-forms](https://github.com/Julien-R44/unocss-preset-forms), that only rely on rules/variants/preflights will work. |
| [@unocss/preset-typography](https://github.com/unocss/unocss/tree/main/packages/preset-typography) || Using the `.prose` class adds a large amount of rulesets which Svelte Scoped will not properly surround with `:global()` wrappers so add the `prose` class to your safelist when using this preset. All other classes from this preset, e.g. `prose-pink`, can be component scoped. |
| [@unocss/preset-rem-to-px](https://github.com/unocss/unocss/tree/main/packages/preset-rem-to-px) || This and all presets like it that only modify style output will work. |
| [@unocss/preset-attributify](https://github.com/unocss/unocss/tree/main/packages/preset-attributify) | - | Use the [unplugin-attributify-to-class](https://github.com/MellowCo/unplugin-attributify-to-class) Vite plugin, updating the include option: `attributifyToClass({ include: [/\.svelte$/]})` |
| [@unocss/preset-attributify](https://github.com/unocss/unocss/tree/main/packages/preset-attributify) | - | Preset won't work. Instead use [unplugin-attributify-to-class](https://github.com/MellowCo/unplugin-attributify-to-class) Vite plugin (`attributifyToClass({ include: [/\.svelte$/]})`) before the Svelte Scoped Vite plugin |
| [@unocss/preset-tagify](https://github.com/unocss/unocss/tree/main/packages/preset-tagify) | - | Presets that add custom extractors will not work. Create a preprocessor to convert `<text-red>Hi</text-red>` to `<span class="text-red">Hi</span>`, then create a PR to add the link here. |

For other presets, if they don't rely on traditional `class="..."` usage you will need to first preprocess those class names into the `class="..."` attribute. If they add extremely complex styles like typography's `.prose` class then you may need to place the complex class names into your safelist.
Expand Down
2 changes: 1 addition & 1 deletion examples/sveltekit-preprocess/vite.config.ts
@@ -1,5 +1,5 @@
import { sveltekit } from '@sveltejs/kit/vite'
import { defineConfig } from 'vitest/config'
import { defineConfig } from 'vite'
import UnoCSS from '@unocss/svelte-scoped/vite'

export default defineConfig({
Expand Down
6 changes: 5 additions & 1 deletion packages/svelte-scoped/src/vite/getReset.ts
Expand Up @@ -8,10 +8,14 @@ const _dirname = typeof __dirname !== 'undefined'

export function getReset(injectReset: string): string {
if (injectReset.startsWith('@unocss/reset')) {
const resolvedPNPM = resolve(resolve(_dirname, `../node_modules/${injectReset}`))
const resolvedPNPM = resolve(resolve(_dirname, `../../../${injectReset}`))
if (isFile(resolvedPNPM))
return readFileSync(resolvedPNPM, 'utf-8')

const resolvedPNPM_in_uno_repo = resolve(resolve(_dirname, `../node_modules/${injectReset}`))
if (isFile(resolvedPNPM_in_uno_repo))
return readFileSync(resolvedPNPM_in_uno_repo, 'utf-8')

const resolvedNPM = resolve(process.cwd(), 'node_modules', injectReset)
if (isFile(resolvedNPM))
return readFileSync(resolvedNPM, 'utf-8')
Expand Down

0 comments on commit 153d158

Please sign in to comment.