-
Notifications
You must be signed in to change notification settings - Fork 0
/
react-vite-tailwind.sh
75 lines (62 loc) · 1.69 KB
/
react-vite-tailwind.sh
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
#!/bin/bash
set -euo pipefail # enable strict mode
# Initialize variables
default_template="react"
typescript=""
tailwind_init="@tailwind base;\n@tailwind components;\n@tailwind utilities;\n"
app_code='
function App() {
return (
<div className="App">
Hello World
</div>
);
}
export default App;'
prettier_config='module.exports = {
plugins: [require("prettier-plugin-tailwindcss")],
};'
# Parse command line arguments
if [[ "${1:-}" == "ts" ]]; then
typescript=" with TypeScript"
default_template+="-$1"
fi
# Install and configure Vite with React template
echo "Installing React${typescript}..."
npm create vite@latest . -- --template "$default_template"
# Install and configure TailwindCSS
echo "Installing TailwindCSS..."
npm install -D tailwindcss postcss autoprefixer
npx tailwindcss init -p
# Create TailwindCSS configuration file
tailwind_config='/** @type {import("tailwindcss").Config} */
module.exports = {
content: [
"./index.html",
"./src/**/*.{js,ts,jsx,tsx}",
],
theme: {
extend: {},
},
plugins: [],
};'
echo "$tailwind_config" > tailwind.config.js
echo "$tailwind_config" > tailwind.config.cjs
# Create TailwindCSS CSS file
echo -e "$tailwind_init" > ./src/index.css
rm src/App.css
# Create React app file
echo "$app_code" > src/App.jsx
# Install and configure Prettier with TailwindCSS plugin
echo "Installing Prettier for Tailwind..."
npm install -D prettier prettier-plugin-tailwindcss
echo "$prettier_config" > prettier.config.cjs
# Initialize Git repository (if installed)
if command -v git >/dev/null 2>&1; then
git init
echo 'node_modules' > .gitignore
git add .
git commit -m "Initial commit"
fi
# Open project in default code editor
code .