Copy npx create-next-app@latest my-project --typescript --eslint
cd my-project
Copy npm install -D tailwindcss postcss autoprefixer
or yarn add -D tailwindcss postcss autoprefixer
npx tailwindcss init -p
Chú ý: Cài đặt tailwindcss v3 chúng ta chỉ định trong package.json
Copy /** @type {import('tailwindcss').Config} */
module.exports = {
content: [
"./app/**/*.{js,ts,jsx,tsx,mdx}",
"./pages/**/*.{js,ts,jsx,tsx,mdx}",
"./components/**/*.{js,ts,jsx,tsx,mdx}",
// Or if using `src` directory:
"./src/**/*.{js,ts,jsx,tsx,mdx}",
],
theme: {
extend: {},
},
plugins: [],
}
Copy @tailwind base;
@tailwind components;
@tailwind utilities;
Copy export default function Home() {
return (
<h1 className="text-3xl font-bold underline">
Hello world!
</h1>
)
}
Copy Usage:
tailwindcss [options]
Options:
-i, --input ··········· Input file
-o, --output ·········· Output file [default: `-`]
-w, --watch ··········· Watch for changes and rebuild as needed
-m, --minify ·········· Optimize and minify the output
--optimize ········ Optimize the output without minifying
--cwd ············· The current working directory [default: `.`]
-h, --help ············ Display usage information
Copy app npx tailwindcss -i ./src/App.css -o ./src/output.css --watch
Copy export default {
plugins: {
"@tailwindcss/postcss": {},
}
}
Một giải pháp hoàn hảo cho v4
Copy yarn add npm-run-all --dev
Copy "start": "react-scripts start",
"watch:tailwindcss": "npx tailwindcss -i ./src/App.css -o ./src/output.css -w",
"watch:start": "react-scripts start",
"dev": "npm-run-all --parallel watch:*",
Copy export default {
plugins: [
"@tailwindcss/postcss"
],
};
Copy import React from 'react';
import './output.css';
function App() {
return (
<div className="columns-3">
App
</div>
);
}
export default App;