# Rails _6.1.6.1_ 安裝 Tailwind 3 ###### tags: `專案` ## 一 、 建立 6.1.6.1 專案 ```shell= rails _6.1.6.1_ new myprojectV3 ``` ```shell= cd myprojectV3 ``` ## 二 、 安裝 tailwind 1. 安裝臨時 tailwindcss 版號,以利執行 init 步驟 ```shell= yarn add -D tailwindcss ``` ```shell= yarn tailwindcss init ``` ```shell= code . ``` 2. 找到 **postcss.config.js** 檔案 在 postcss.config.js 加上 `require('tailwindcss')`  3. 在 app/javascript/ 建立一個檔案 **application.css**  貼上這幾行 ```css= @import "tailwindcss/base"; @import "tailwindcss/utilities"; @import "tailwindcss/components"; ```  4. 依據 app/javascript/packs/ 這條路徑找到 application.js ,在裡面新增 ```js= import "../application.css" ```  5. 移除臨時 tailwindcss 版號 ```shell= yarn remove tailwindcss ``` 6. 安裝正式 tailwindcss 版號 ```shell= yarn add -D tailwindcss@npm:@tailwindcss/postcss7-compat ``` ## 三 、 測試是否成功 1. 建立一個 UserController 並具有 index 方法 ```rb= rails g controller users index ``` 2. 建立根目錄 ```rb= root 'users#index' ```  3. 在 index.html.erb 設定最後的 tailwind 測試樣式 ```html= <h1 class="text-9xl font-bold underline">終於要完成了</h1> ```  4. 啟動伺服器 ```shell= rails s ```  5. 查看版本 ```shell= npm view tailwindcss version ``` ## 四 、 前後比較 ### 失敗   ### 成功 **(不會有 stylesheet_link_tag 'tailwind')** 
×
Sign in
Email
Password
Forgot password
or
By clicking below, you agree to our
terms of service
.
Sign in via Facebook
Sign in via Twitter
Sign in via GitHub
Sign in via Dropbox
Sign in with Wallet
Wallet (
)
Connect another wallet
New to HackMD?
Sign up