Closed2
hono SSR, tailwindcss 短縮表記
概要
honoで、tailwindcss npm版追加して。短縮表記となります
環境
- hono
- tailwindcss
- workers
npm install -D tailwindcss postcss autoprefixer
npx tailwindcss init
- postcss.config.js
module.exports = {
plugins: {
tailwindcss: {},
autoprefixer: {},
}
}
- tailwind.config.js, public/ ついか
/** @type {import('tailwindcss').Config} */
module.exports = {
content: ["./src/**/*.{html,js,ts,tsx}", "./public/**/*.{html,js,ts,tsx}"],
theme: {
extend: {},
},
plugins: [],
}
- main.css, btnついか
@tailwind base;
@tailwind components;
@tailwind utilities;
/* custom_class */
.container_base {
@apply container mx-auto px-8 bg-white;
}
/* button */
.btn {
@apply bg-blue-500 hover:bg-blue-700 text-white font-bold py-2 px-4 rounded;
}
コンパイル
- watchモードは、自動出力されるので便利です
npx tailwindcss -i ./src/main.css -o ./public/styles/main.css --watch
- 単発実行
npx tailwindcss -i ./src/main.css -o ./public/styles/main.css
読込
- layout.tsx
{html`
<link href="/styles/main.css" rel="stylesheet">
`}
関連のコード
- package.json
{
"name": "hono_jsx4",
"version": "1.0.0",
"description": "",
"main": "index.js",
"scripts": {
"start": "wrangler dev src/index.tsx",
"deploy": "wrangler deploy --minify src/index.tsx",
"test": "echo \"Error: no test specified\" && exit 1"
},
"keywords": [],
"author": "",
"license": "ISC",
"devDependencies": {
"@cloudflare/workers-types": "^4.20230922.0",
"autoprefixer": "^10.4.16",
"postcss": "^8.4.31",
"tailwindcss": "^3.3.3",
"wrangler": "^3.10.0"
},
"dependencies": {
"hono": "^3.7.2"
}
}
このスクラップは2023/10/02にクローズされました