Crafting a Beautiful Web Theme: A Guide to Building Themes with Vite, Alpine.js, and Tailwind CSS in JavaScript

Raviya Technical
2 min readNov 26, 2023

--

npm create vite@latest my-new-app --template=vanilla

Adding new lastest Alpine.js and Tailwind CSS

npm install -D tailwindcss postcss autoprefixer
npx tailwindcss init
npm install alpinejs --save

Config tailwind.config.cjs file

/** @type {import('tailwindcss').Config} */
export default {
content: [
"./index.html", // don't forget to add other files and directories
"./src/**/*.{js,ts,jsx,tsx}",
],
theme: {
extend: {},
},
plugins: [],
}

Change postcss.config.cjs

module.exports = {
plugins: {
tailwindcss: {},
autoprefixer: {},
}
}

Replace code style.css and main.js

style.css

@tailwind base;
@tailwind components;
@tailwind utilities;

main.js

import './style.css'
import Alpine from 'alpinejs'
window.Alpine = Alpine
Alpine.start()

creating a index.html in public folder

<!doctype html>
<html lang="en">

<head>
<meta charset="UTF-8" />
<link rel="icon" type="image/svg+xml" href="https://vitejs.dev/logo.svg" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<title>Vite App</title>
</head>

<body class="flex h-screen">
<div class="m-auto" x-data="{ count: 0 }">
<div class="flex gap-2">
<a href="https://vitejs.dev" target="_blank">
<img src="https://vitejs.dev/logo.svg" class="h-10" alt="Vite logo" />
</a>
<a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript" target="_blank">
<img src="data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAALoAAAC6CAMAAAAu0KfDAAAAdVBMVEX33x4AAAD/5h/HtBi6qBcZFgMxLAb/6iD85B//6B+FeBD64R7/7SD03R4vKgbPuxmklBTgyhtxZg40Lwbs1R3m0BwgHQRLQwl6bg+unRXVwBo9NwcdGgSXiBJSSgqMfxEmIwRqYA0KCQFaUgtkWgwSEQJEPgjaH22TAAAGDUlEQVR4nO2b61azOhBACUFJCNcWLAT5erH6/o94oGpLSUKC0NCz1uy/WtyOk5CZjI4DAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA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r1RR0rhAJqv6C6n38F4h/R9YavlDcsqPv55bxSqWsQ8U57MXVG8gahWBzLokJj6zBIDEainynHd+WhihXC1r5UwriRdwmLpG4UTiGD+Sc3967d0p2qz0K4kOvVIsuU+fw69zGIGyuE65Ytu/so7l8+fuRyd1+s+sS0+wPUaa6L6G0QN8mu9nWrLJkflfeZcJaOMVAx6GiBo2Mbt/7q/7yb7pcNApbXJGUsHe6cqE5cwckVMx2h+eKsGNw2x9mtj09kV1zXu2jJeEBHUNy9ndpTu/BqaDnPNi9SYRx3W2WUuoS4NOKyPuJtJUfyf8w4pEnudk/onkFzHMgaeuncfJH3Zz/2Fca4asrhGaDj9bapkUQSzov8sX1CwjPePmQjHVU+8dmprriOeIlfY8V0dNNbx0zd3T3F27rexqri9JjPVVdcNY/R3xlYNPnjP6hfvMbQyqCz3Ce4KxEonzC53uM8O+jd7mdyG3HjMHjX+5IiQs/LIhMzJB/vsQ0Ihp93jf9Lo0e5TJnhJhN+Zi1M0zHxkKNnqZmNCUP/J8lVEJsc99Ny87GkMl1rjawxzvx00uz9dqSamgpzKrN83ysWV+hN+JeH3YLm3THDKN8bZQHnZiY3jxc2S1+dkkIbt09vZHEx+QSYSLr8VBXzq9HJkPdzNF6QkTCtdWkXl4+ZcfDzRhn5w9Gj2gylTrUZuzjdBfxR173Mz6pAmC1G3UAIjkzefm3NlKQb+WGyDir+yDkwQqIsac79v3tdVrwtHQwfwAjJM5wOgl9v0iSLHj6IxLpBrfYX8Fowz9s9ZbQhJ39A+4GCY6+qqsszut/I3mBAV964cwZEGXHbR8x7BgAAAAAAAPA4/gMhkFZhpB+AswAAAABJRU5ErkJggg==" class="h-10" alt="JavaScript logo" />
</a>
<a href="https://tailwindcss.com" target="_blank">
<img src="https://tailwindcss.com/favicons/favicon-32x32.png?v=3" class="h-10" alt="Vite logo" />
</a>
<a href="https://alpinejs.dev" target="_blank">
<img src="https://alpinejs.dev/favicon.png" class="h-10" alt="Alpine JS logo" />
</a>
</div>
<div class="mt-4 text-center">
<span x-text="count" class="text-3xl"></span>
<div class="flex justify-between mt-4">
<button x-on:click="count--" class="text-red-700 hover:text-white border border-red-700 hover:bg-red-800 focus:ring-4 focus:outline-none focus:ring-red-300 font-medium rounded-lg text-sm px-2 py-1 text-center me-2 mb-2 dark:border-red-500 dark:text-red-500 dark:hover:text-white dark:hover:bg-red-500 dark:focus:ring-red-800">Decrement</button>
<button x-on:click="count++" class="text-blue-700 hover:text-white border border-blue-700 hover:bg-blue-800 focus:ring-4 focus:outline-none focus:ring-blue-300 font-medium rounded-lg text-sm px-2 py-1 text-center me-2 mb-2 dark:border-blue-500 dark:text-blue-500 dark:hover:text-white dark:hover:bg-blue-500 dark:focus:ring-blue-800">Increment</button>
</div>
</div>
</div>
<script type="module" src="/main.js"></script>
</body>

</html>

Now running dev mode

npm run dev 
Crafting a Beautiful Web Theme: A Guide to Building Themes with Vite, Alpine.js, and Tailwind CSS in JavaScript

Full Code In Link

Support Links

--

--

No responses yet