Deploy  React & Vite App ไปยัง GitHub (Host Static-Website with AWS Amplify Part. 2)

Deploy React & Vite App ไปยัง GitHub (Host Static-Website with AWS Amplify Part. 2)

ในบทความนี้เป็นบทความและวิธีการ Deploy React+Vite App ไปยัง GitHub เพื่อทำ Host a Static Website ด้วย AWS Amplify โดยเราไม่ต้อง build และ upload manual เป็นวิธีที่ประหยัดเวลาในการ deploy วิธีหนึ่งครับ บทความนี้ผมได้ทำการทดลองสำเร็จและอยากเอามาแชร์ให้เพื่อนๆได้อ่านกันและทำตามครับ
2026.03.10

สวัสดีครับ เบิร์ด จาก ClassMethod Thailand

บทความนี้เป็นส่วนหนึ่งของซีรีย์บทเรียน "สร้าง Host Static Website ด้วย React และ AWS Amplify" ที่ผมได้ทำการทดลองเลยอยากเอามาแชร์ให้เพื่อนๆได้อ่านกันและทำตาม โดยเนื้อหาในแต่ละบทความสามารถทำตามได้เป็นอิสระ แต่หากทำตามทุกขั้นตอนต่อเนื่องกัน จะมีลักษณะดังนี้
1.สร้าง React Application
2.Deploy React & Vite App ไปยัง GitHub
3.Deploy React แอปพลิเคชันด้วย AWS Amplify

ในบทความนี้จะเป็น Part 2 : Deploy React & Vite App ไปยัง GitHub

บทความนี้อ้างอิงจากเอกสารด้านล่างนี้
Ref:

https://docs.aws.amazon.com/hands-on/latest/host-static-website/host-static-website.html

ข้อดีของการ Deploy React Vite App ไปยัง GitHub

  1. ฟรีและไม่จำกัด 💰
    ไม่มีค่าใช้จ่ายสำหรับ public repositories
    Bandwidth ไม่จำกัด (มีข้อจำกัดบางอย่างแต่เพียงพอสำหรับโปรเจกต์ส่วนใหญ่)

  2. ง่ายและรวดเร็ว ⚡
    Build time เร็วด้วย Vite
    Push code แล้วเว็บอัปเดตเอง

  3. เหมาะกับ Vite 🚀
    Build เร็วกว่า Create React App มาก
    Hot Module Replacement (HMR) ที่รวดเร็ว

  4. Version Control ในตัว 📝
    ติดตาม history ของการ deploy ทั้งหมด
    Rollback ได้ง่ายถ้ามีปัญหา
    เห็นการเปลี่ยนแปลงทุกครั้ง

  5. Custom Domain ได้ 🌐
    รองรับ custom domain ฟรี

สิ่งที่ต้องมี :

  1. Create the React application ตามรูปด้านล่าง ซึ่งในบทความนี้เราได้ทำการสร้าง app มาแล้ว
    เรามาเริ่ม Create New Repository กันเลย

https://dev.classmethod.jp/articles/React-Static-Website-TH/

f1-1-mo

Create New Repository.

1. Open GitHub

Sign in to GitHub at https://github.com/.
เนื่องจากเราได้สร้างบัญชีแล้ว เราสามารถกด NEW ได้เลย

f1-2-mo

2. Repository name: enter staticwebsite

d2-1m

3. Config : ⇒ public ⇒ Create repository

d3

หลังจาก Create repository แล้วเราจะเห็นหน้าต่างขึ้นมา

d3-1m

Push the Application ไปยัง GitHub

อัปโหลดแอปพลิเคชันไปยัง GitHub

เปิดหน้าต่างเทอร์มินัลใหม่ ไปที่โฟลเดอร์รากของโปรเจ็กต์ของคุณ (staticwebsite) และเรียกใช้คำสั่งต่อไปนี้เพื่อเริ่มต้น Git
และอัปโหลดแอปพลิเคชันไปยังที่เก็บ GitHub ใหม่:

ก่อนจะเริ่มเรามาตรวจสอบว่ามีไฟล์อะไรบ้างที่จำเป็น

 dir 

d4-1m

คำสั่งที่ 1 : สร้าง Git Repository

git init 

d5-1m

คำสั่งที่ 2 : Warning ที่เห็น เป็นเรื่องปกติ (เกี่ยวกับการแปลง line endings จาก LF เป็น CRLF บน Windows) ไม่มีปัญหาครับ

git add . 

d6-2

คำสั่งที่ 3: Commit ไฟล์

git commit -m "first commit"

d7-1m

คำสั่งที่ 4: เชื่อมต่อกับ GitHub
อธิบาย : xxxx คือ GitHub username ของตัวเอง

git remote add origin https://github.com/xxxx/staticwebsite.git

d8-1m

คำสั่งที่ 5: เปลี่ยน branch เป็น main

git branch -M main

คำสั่งที่ 6: Push ขึ้น GitHub (คำสั่งสุดท้าย)

git push -u origin main

คลิก "Sign in with your browser"

d9-1m

หลังจากคลิก "Authorize git-ecosystem" แล้ว:

d11

เท่านี้เราก็สามารถ Push the application ไปยัง GitHub แล้วครับ
***เราจะเห็น file project เข้ามาอยู่ใน GitHub ของเราแล้วครับ

d10-1m

สรุป

  1. โค้ดจะถูก Push ขึ้น GitHub สำเร็จ
  2. กลับไปดูที่ Terminal จะเห็นข้อความ Push สำเร็จ
  3. ไปดูที่ GitHub Repository จะเห็นไฟล์ทั้งหมด

บทความอ้างอิง

https://docs.aws.amazon.com/hands-on/latest/host-static-website/host-static-website.html

บทความอื่นๆที่เกี่ยวข้องกับ AWS Amplify

(Thai)
https://dev.classmethod.jp/articles/React-Static-Website-TH/

https://dev.classmethod.jp/articles/what-is-aws-amplify/

https://dev.classmethod.jp/articles/static-web-hosting-serverless-aws-amplify/

(Japanese)

https://dev.classmethod.jp/articles/reintroduction-aws-amplify/

この記事をシェアする

FacebookHatena blogX

関連記事