Astro 集成
Astro 的 UnoCSS 集成:@unocss/astro
。查看 示例。
安装
bash
pnpm add -D unocss
bash
yarn add -D unocss
bash
npm install -D unocss
ts
// astro.config.ts
import { defineConfig } from 'astro/config'
import UnoCSS from 'unocss/astro'
export default defineConfig({
integrations: [
UnoCSS(),
],
})
创建 uno.config.ts
文件:
ts
// uno.config.ts
import { defineConfig } from 'unocss'
export default defineConfig({
// ...UnoCSS 选项
})
样式重置
默认情况下,浏览器样式重置不会被注入。要启用它,请安装 @unocss/reset
包:
bash
pnpm add -D @unocss/reset
bash
yarn add -D @unocss/reset
bash
npm install -D @unocss/reset
并更新你的 astro.config.ts
:
ts
// astro.config.ts
import { defineConfig } from 'astro/config'
import UnoCSS from 'unocss/astro'
export default defineConfig({
integrations: [
UnoCSS({
injectReset: true // 或重置文件的路径
}),
],
})
不带预设
此插件没有任何默认预设。
bash
pnpm add -D @unocss/astro
bash
yarn add -D @unocss/astro
bash
npm install -D @unocss/astro
ts
// astro.config.mjs
import UnoCSS from '@unocss/astro'
export default {
integrations: [
UnoCSS(),
],
}
更多详情,请参考 Vite 插件。
警告
如果你正在构建基于 UnoCSS 的元框架,请参见此文件,了解如何绑定默认预设。
注意事项
client:only
组件必须放置在 components
文件夹中,或添加到 UnoCSS 的 content
配置中,以便被处理。