0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

Viteのプロジェクトにtailwindcss入れたけど動かないときにやったこと

Posted at

tauriでフロントエンドをvite+ts+reactにしてtailwindcss入れてみたけどなんか動かんな?ってなったときの備忘録
結論から言うとtailwindautoprefixervite.config.tspluginsに記載すると動きました

公式サイトでは以下の設定すれば使えるよ!とありました

  1. npm install -D tailwindcss postcss autoprefixer npx tailwindcss init -p
  2. tailwind.config.jscontentを追加して、必要なファイル(htmlやts,tsx)を追加する
  3. index.cssつくって@tailwindの命令を書いてApp.tsxなどからimport
  4. コードからtailwindのクラスを呼ぶ

ところが上記だけでは動かなかったので、vite.config.tsに以下追加すると動きました

import { defineConfig } from "vite";
import react from "@vitejs/plugin-react";
+import tailwind from "tailwindcss";
+import autoprefixer from "autoprefixer";

export default defineConfig(async () => ({
  plugins: [react()],
+ css: {
+   postcss: {
+     plugins: [tailwind, autoprefixer]
+   }
+ },

  // Vite options tailored for Tauri development and only applied in `tauri dev` or `tauri build`
  //
  // 1. prevent vite from obscuring rust errors
  clearScreen: false,
  // 2. tauri expects a fixed port, fail if that port is not available
  server: {
    port: 1420,
    strictPort: true,
    host: host || false,
    hmr: host
      ? {
          protocol: "ws",
          host,
          port: 1421
        }
      : undefined,
    watch: {
      // 3. tell vite to ignore watching `src-tauri`
      ignored: ["**/src-tauri/**"]
    }
  }
}));

0
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?