Website statis modern dengan integrasi Firebase Realtime Database. Cocok untuk toko/bisnis yang ingin punya website dengan konten yang bisa diupdate tanpa perlu deploy ulang.
Masalah: Punya website statis tapi ribet kalau mau ganti harga, menu, atau info kontak. Harus edit code, build ulang, deploy lagi.
Solusi: Website ini mengambil data dari Firebase Realtime Database. Ubah data di database β website langsung update otomatis, tanpa perlu build atau deploy ulang!
- β¨ Update konten tanpa coding - Ubah harga, menu, kontak via Firebase Console
- π Tidak perlu deploy ulang - Perubahan langsung terlihat di website
- π° Gratis - Firebase free tier cukup untuk website toko kecil
- π± Responsive - Tampilan bagus di HP dan desktop
- β‘ Cepat - Static site + Firebase CDN = loading super cepat
- π WhatsApp integration - Form order langsung ke WhatsApp
-
Nomor WhatsApp harus bisnis, bukan personal
- Data diambil secara berkala dari database
- WhatsApp personal bisa kena limit/banned kalau terlalu banyak request
- Solusi: Pakai WhatsApp Business API atau nomor bisnis
-
Data bisa dibaca orang lain
- API Firebase yang dipakai untuk read data bisa dilihat di browser (inspect element)
- Orang lain bisa pakai API yang sama untuk ambil data menu/harga Anda
- Bahkan kalau JavaScript di-compile jadi 1 line, API endpoint tetap kelihatan
- Solusi ke depan:
- Pakai Firebase Security Rules yang lebih ketat (batas rate limit, domain whitelist)
- Atau pakai backend API dengan authentication
- Atau enkripsi data sensitif
-
Perlu setup awal
- Harus setup Firebase project dulu
- Perlu sedikit technical knowledge untuk setup pertama kali
- Toko kue, donut, bakery
- Cafe, warung makan
- Toko online kecil
- Bisnis yang sering update harga/menu
- Yang mau website simple tapi fleksibel
sweetcrumb/
βββ src/ # Source files (edit these)
β βββ index.html # Main HTML template
β βββ main.ts # TypeScript entry point
β βββ firebase-loader.ts # Firebase logic
β βββ vite-env.d.ts # TypeScript env definitions
β βββ styles/
β βββ main.scss # SCSS styles
βββ public/ # Build output (auto-generated, gitignored)
β βββ index.html # Compiled HTML
β βββ index.css # Compiled CSS (from SCSS)
β βββ main.js # Compiled JavaScript (from TypeScript)
β βββ static/ # Images (if any)
βββ .env # β οΈ PRIVATE - Your Firebase credentials (gitignored)
βββ .env.example # Template for environment variables
βββ .firebaserc # β οΈ PRIVATE - Your Firebase project ID (gitignored)
βββ .firebaserc.example # Template for Firebase project config
βββ firebase.json # Firebase Hosting configuration
βββ database.rules.json # Firebase Database security rules
βββ package.json # Dependencies & scripts
βββ tsconfig.json # TypeScript configuration
βββ vite.config.ts # Vite build configuration
npm installInstalls: TypeScript, Vite, SASS, Firebase SDK
cp .env.example .env
# Edit .env and fill in your Firebase credentials
cp .firebaserc.example .firebaserc
# Edit .firebaserc and fill in your Firebase project IDnpm run dev
# Opens at http://localhost:5173npm run build
# Output in public/ foldernpm run deploy
# Or: firebase deployFirebase API keys are safe to expose in frontend code. Firebase security is handled by Security Rules, not by hiding API keys.
Your .env file contains:
VITE_FIREBASE_API_KEY=your_api_key
VITE_FIREBASE_AUTH_DOMAIN=your_project.firebaseapp.com
VITE_FIREBASE_DATABASE_URL=https://your_project.firebaseio.com
VITE_FIREBASE_PROJECT_ID=your_project_id
VITE_FIREBASE_STORAGE_BUCKET=your_project.appspot.com
VITE_FIREBASE_MESSAGING_SENDER_ID=your_sender_id
VITE_FIREBASE_APP_ID=your_app_idNote: .env is gitignored. Team members should copy .env.example and fill in their own credentials.
β Committed to Git:
src/- Source code.env.example- Template for environment variables.firebaserc.example- Template for Firebase project configfirebase.json- Firebase Hosting configurationdatabase.rules.json- Firebase Database security rulespackage.json- Dependenciesvite.config.ts- Build configtsconfig.json- TypeScript configREADME.md- This file
β Gitignored (NOT committed):
.env- Your Firebase credentials.firebaserc- Your Firebase project IDnode_modules/- Dependencies (runnpm install)public/- Build output (runnpm run build).firebase/- Firebase cache
When you run npm run build:
- TypeScript compiles to JavaScript β
public/main.js - SCSS compiles to CSS β
public/index.css - HTML is processed β
public/index.html - Environment variables are injected into the code
- Files are minified and optimized
- Images (if any) go to
public/static/
Build Output Structure:
public/
βββ index.html # Main HTML file
βββ index.css # Compiled & minified CSS
βββ main.js # Compiled & minified JavaScript
βββ static/ # Images and other assets
Firebase Hosting serves the public/ folder (configured in firebase.json).
For new team members:
- Clone the repo
- Run
npm install - Copy
.env.exampleto.env - Copy
.firebaserc.exampleto.firebaserc - Fill in Firebase credentials in
.env(get from Firebase Console) - Fill in Firebase project ID in
.firebaserc - Run
npm run dev
Firebase credentials location:
- Go to Firebase Console
- Select your project
- Project Settings β General β Your apps β Config
- Copy the values to your
.envfile
| Command | Description |
|---|---|
npm run dev |
Start development server (hot reload) |
npm run build |
Build for production |
npm run preview |
Preview production build locally |
npm run deploy |
Build and deploy to Firebase Hosting |
{
"config": {
"WA_NUMBER": "628xxxxxxxxxx",
"STORE_STREET": "Jl. Example No. 123",
"STORE_DISTRICT": "District Name",
"STORE_CITY": "City, Province 12345",
"STORE_HOURS": "Mon-Sat 08:00-20:00"
},
"menu": {
"000_CLASSIC_DONUT": {
"name": "Classic Donut",
"description": "...",
"price": 28000,
"tag": "Best Seller",
"type": "Donut",
"image_url": "https://..."
}
}
}- TypeScript - Type safety, better IDE support, fewer bugs
- SCSS - Nested styles, variables, better organization
- Vite - Fast build, hot module replacement, modern tooling
- Environment Variables - Credentials separated from code
- Modern Workflow - Professional setup, easy to maintain
- Clean Build Output - Simple filenames (index.html, index.css, main.js) tanpa hash, mudah di-debug
Project ini dikonfigurasi untuk menghasilkan output yang clean dan mudah dibaca:
- JavaScript:
main.js(bukanmain-[hash].js) - CSS:
index.css(bukanstyle-[hash].css) - HTML:
index.html - Images:
static/[filename](jika ada)
Konfigurasi ini ada di vite.config.ts β rollupOptions β output.
- Firebase API keys in frontend are safe and expected
- Security is enforced via Firebase Security Rules (see
database.rules.json) - Never commit
.envor.firebasercfiles to Git (both are gitignored) - Use Firebase Security Rules to restrict database access
- Private keys (service account keys) should NEVER be in frontend code
Important: Data in Firebase Realtime Database bisa dibaca orang lain jika mereka tahu API endpoint. Untuk production, gunakan Firebase Security Rules yang lebih ketat.
- Make sure Node.js is installed:
node --version - Delete
node_modules/and runnpm installagain
- Check browser console for errors
- Verify
.envfile has correct Firebase credentials - Make sure Firebase Realtime Database rules allow read access
- Check TypeScript errors:
npm run build - Fix any type errors in
src/firebase-loader.ts
- Make sure
src/vite-env.d.tsexists - Restart your IDE/editor
- Make sure
.firebasercfile exists (copy from.firebaserc.example) - Fill in your Firebase project ID in
.firebaserc - Or run:
firebase use --addand select your project
- Delete
node_modules/andpackage-lock.json - Run
npm installagain - Restart your development server
Private project for Sweet Crumb.