JavaScript2021-05-211 min read
Sử dụng Tailwind CSS trong NextJS
NextJS là framework cho phép chúng ta thực hiện Server Side Rendering (SSR). Tailwind CSS là một utility-first CSS framework cho phép chúng ta tạo style cho trang web mà không cần viết nhiều CSS.
Nguyen Pham
•Xin chào. Mình thích lập trình và công nghệ. Đây là blog mình chia sẻ lại các kiến thức về lập trình, công nghệ.
NextJS là framework cho phép chúng ta thực hiện Server Side Rendering (SSR)
Tailwind CSS là một utility-first CSS framework cho phép chúng ta tạo style cho trang web mà không cần viết nhiều CSS.
1. Cài đặt#
Tạo nextjs app
codenpx create-next-app next-tailwindcss cd next-tailwindcss
Cài đặt Tailwind CSS
yarn install -D tailwindcss@latest postcss@latest autoprefixer@lates
2. Cấu hình#
Tạo config Tailwind CSS: tailwind.config.js , postcss.config.js
npx tailwindcss init -p
tailwind.config.js
codemodule.exports = { mode: "jit", purge: ['./pages/**/*.{js,ts,jsx,tsx}', './components/**/*.{js,ts,jsx,tsx}'], darkMode: false, // or 'media' or 'class' theme: { extend: {}, }, variants: { extend: {}, }, plugins: [], };
postcss.config.js
codemodule.exports = { plugins: { tailwindcss: {}, autoprefixer: {}, }, }
package.json
code{ "name": "next-tailwindcss", "version": "0.1.0", "private": true, "scripts": { "dev": "next dev", "build": "next build", "start": "next start" }, "dependencies": { "next": "10.2.2", "react": "17.0.2", "react-dom": "17.0.2" }, "devDependencies": { "autoprefixer": "^10.2.5", "postcss": "^8.3.0", "tailwindcss": "^2.1.2" } }
3. Chạy#
yarn dev
Tham khảo:
Tags:#JavaScript#Programming#css#javascript#nextjs#react#tailwindcss