Skip to content

設定ファイル

IDEやその他の統合機能で最高の体験を得るために、UnoCSSの設定には専用のuno.config.tsファイルを使用することを強く推奨します。

完全な機能を持つ設定ファイルは以下のようになります:

ts
import {
  defineConfig,
  presetAttributify,
  presetIcons,
  presetTypography,
  presetWebFonts,
  presetWind3,
  transformerDirectives,
  transformerVariantGroup
} from 'unocss'

export default defineConfig({
  shortcuts: [
    // ...
  ],
  theme: {
    colors: {
      // ...
    }
  },
  presets: [
    presetWind3(),
    presetAttributify(),
    presetIcons(),
    presetTypography(),
    presetWebFonts({
      fonts: {
        // ...
      },
    }),
  ],
  transformers: [
    transformerDirectives(),
    transformerVariantGroup(),
  ],
})

vite.config.tsやその他のツール設定内のインライン設定と比較して、専用の設定ファイルはIDEや統合機能、ESLintプラグインなどの他のツールでより良く動作し、さらにHMRの動作も改善されます。

デフォルトでは、UnoCSSはプロジェクトのルートディレクトリでuno.config.{js,ts,mjs,mts}またはunocss.config.{js,ts,mjs,mts}を自動的に探します。設定ファイルを手動で指定することもできます。例えば、Viteの場合:

ts
import UnoCSS from 'unocss/vite'
import { defineConfig } from 'vite'

export default defineConfig({
  plugins: [
    UnoCSS({
      configFile: '../my-uno.config.ts',
    }),
  ],
})

サポートされている設定オプションの完全なリストについては、設定リファレンスを参照してください。

Released under the MIT License.