Install tailwindcss in vue

York Chen
3 min readAug 17, 2020

--

1.用NPM或yarn安裝

# Using npm

npm install tailwindcss

# Using Yarn

yarn add tailwindcss

2.設定postcss.config.js

專案路徑:postcss.config.js

module.exports = {
plugins: [
require('tailwindcss'),
require('autoprefixer')({
grid: true,
overrideBrowserslist: [
'> 1%',
'last 5 versions',
'Firefox >= 45',
'ios >= 8',
'ie >= 10'
]
})
]
}

3.設定app.css

專案路徑:src\assets\style\app.css

@tailwind base;

@tailwind components;

@tailwind utilities;

4.設定 main.js

專案路徑:src\main.js
import'@/assets/style/app.css'

5.設定 tailwind.config.js

專案路徑:tailwind.config.js

module.exports = {
purge: [
"./pages/**/*.vue",
"./views/*.vue",
"./components/**/*.vue",
"./plugins/**/*.vue",
"./static/**/*.vue",
"./store/**/*.vue"
],
theme: {},
variants: {},
plugins: []
};

6.在VUE中使用tailwindcss

專案路徑:src\App.vue

<div id="app" class="bg-blue-500">

7.響應式例子

Source Code:

https://codepen.io/tcssh611503/pen/ZEWOGKV

--

--

York Chen
York Chen

Written by York Chen

Cooking is an indispensable part of life. It is a taste that can’t be forgotten.

No responses yet