Skip to content

Commit

Permalink
fix(astro)!: disable injected reset styles by default (#2377)
Browse files Browse the repository at this point in the history
Co-authored-by: Anthony Fu <anthonyfu117@hotmail.com>
  • Loading branch information
Hongbusi and antfu committed Apr 9, 2023
1 parent 8baeaf8 commit 11864ad
Show file tree
Hide file tree
Showing 6 changed files with 44 additions and 9 deletions.
37 changes: 35 additions & 2 deletions docs/integrations/astro.md
Original file line number Diff line number Diff line change
Expand Up @@ -23,13 +23,14 @@ The UnoCSS integration for [Astro](https://astro.build/): `@unocss/astro`. Check

```ts
// astro.config.ts
import { defineConfig } from 'astro/config'
import UnoCSS from 'unocss/astro'

export default {
export default defineConfig({
integrations: [
UnoCSS(),
],
}
})
```

Create a `uno.config.ts` file:
Expand All @@ -43,6 +44,38 @@ export default defineConfig({
})
```

### Style Reset

By default, [browser style reset](/guide/style-reset) will not be injected. To enable it, install the `@unocss/reset` package:

::: code-group
```bash [pnpm]
pnpm add -D @unocss/reset
```
```bash [yarn]
yarn add -D @unocss/reset
```
```bash [npm]
npm install -D @unocss/reset
```
:::

And update your `astro.config.ts`:

```ts
// astro.config.ts
import { defineConfig } from 'astro/config'
import UnoCSS from 'unocss/astro'

export default defineConfig({
integrations: [
UnoCSS({
injectReset: true // or a path to the reset file
}),
],
})
```

### Usage without presets

This plugin does not come with any default presets.
Expand Down
2 changes: 1 addition & 1 deletion examples/astro-vue/astro.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,6 @@ import vue from '@astrojs/vue'
export default defineConfig({
integrations: [
vue(),
UnoCSS(),
UnoCSS({ injectReset: true }),
],
})
1 change: 1 addition & 0 deletions examples/astro-vue/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
},
"devDependencies": {
"@astrojs/vue": "^2.1.0",
"@unocss/reset": "link:../../packages/reset",
"astro": "^2.1.9",
"unocss": "link:../../packages/unocss"
}
Expand Down
2 changes: 1 addition & 1 deletion examples/astro/astro.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,6 @@ import UnoCSS from 'unocss/astro'

export default defineConfig({
integrations: [
UnoCSS(),
UnoCSS({ injectReset: true }),
],
})
1 change: 1 addition & 0 deletions examples/astro/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
"astro": "astro"
},
"devDependencies": {
"@unocss/reset": "link:../../packages/reset",
"astro": "^2.1.9",
"unocss": "link:../../packages/unocss"
}
Expand Down
10 changes: 5 additions & 5 deletions packages/astro/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ export interface AstroIntegrationConfig<Theme extends {} = {}> extends VitePlugi
/**
* Include reset styles
* When passing `true`, `@unocss/reset/tailwind.css` will be used
* @default true
* @default false
*/
injectReset?: string | boolean

Expand All @@ -32,7 +32,7 @@ export default function UnoCSSAstroIntegration<Theme extends {}>(
): AstroIntegration {
const {
injectEntry = true,
injectReset: includeReset = true,
injectReset = false,
injectExtra = [],
} = options

Expand All @@ -49,9 +49,9 @@ export default function UnoCSSAstroIntegration<Theme extends {}>(
config.vite.plugins.push(...VitePlugin(options, defaults) as any)

const injects: string[] = []
if (includeReset) {
const resetPath = typeof includeReset === 'string'
? includeReset
if (injectReset) {
const resetPath = typeof injectReset === 'string'
? injectReset
: '@unocss/reset/tailwind.css'
injects.push(`import "${resetPath}"`)
}
Expand Down

0 comments on commit 11864ad

Please sign in to comment.