การลดขนาดแพ็กเกจและพื้นที่ดิสก์
ลดขนาดตัวติดตั้งและพื้นที่ดิสก์ของแอป Electron ด้วยการตัดสิ่งที่ต้องพึ่งพาที่ไม่จำเป็น ใช้ ASAR และลบไฟล์ที่ไม่ได้ใช้งาน เพื่อเสริมการเพิ่มประสิทธิภาพเวลาเริ่มต้นและหน่วยความจำ
การลดขนาดแพ็กเกจและพื้นที่ดิสก์ เป็นบทเรียน Electron Desktop App Development ฟรีบน CoddyKit นี่คือบทเรียนที่ 4 จากทั้งหมด 4 บทเรียน คุณสามารถอ่านบทเรียนทั้งหมดด้านล่างฟรี — จากนั้นลองปฏิบัติด้วยตัวคุณเองในเบราว์เซอร์พร้อมตัวแก้ไขโค้ดในตัวและติวเตอร์ AI ตลอด 24/7 บทเรียนนี้เป็นส่วนหนึ่งของเส้นทางการเรียน Electron Desktop App Development และความก้าวหน้าของคุณจะซิงค์ข้ามเว็บและแอป CoddyKit คอร์ส Electron Desktop App Development มีบทเรียนทั้งหมด 4 บทเรียน
บางส่วนของบทเรียนนี้ยังไม่ได้รับการแปล และแสดงเป็นภาษาอังกฤษ
The Size Problem
Electron apps ship a full Chromium runtime, so they start large. Keeping your code and assets lean is what you can control.
Audit Your Dependencies
Every dependency ships with your app. devDependencies do not. Misplacing a build tool bloats the bundle.
function shipsInApp(dep) {
return dep.type === 'dependency';
}
console.log(shipsInApp({ name: 'lodash', type: 'dependency' }));Prune node_modules
Packagers can run npm prune --production to strip dev packages before bundling.
Use ASAR Archiving
ASAR packs your app files into a single archive, reducing file count and speeding reads.
{
"build": {
"asar": true
}
}Exclude Unneeded Files
Use packager files globs to exclude tests, docs, and source maps from the shipped app.
function include(path) {
return !path.includes('/test/') && !path.endsWith('.map');
}
console.log(include('src/test/spec.js'));Tree-Shake the Renderer
Bundle renderer code with a tool that tree-shakes dead code, and import only what you use.
// good: import only one function
// import { debounce } from 'lodash-es';Prefer Lightweight Libraries
Swap heavy packages for smaller alternatives. A date helper may replace a multi-megabyte library.
Compress Assets
Optimize images and fonts. Use modern formats and subset fonts to only the glyphs you ship.
Native Module Costs
Native modules add platform-specific binaries. Include only the ones you truly need to avoid per-arch bloat.
Measure the Result
Inspect the unpacked app size and installer size before and after changes to confirm real savings.
function deltaMB(before, after) {
return (before - after).toFixed(1) + ' MB saved';
}
console.log(deltaMB(180.4, 142.1));Differential Updates
Smaller bundles also mean smaller delta updates, so users download less on each release.
Quick Check
Test your footprint optimization knowledge.
Recap
You learned to shrink your app: audit and prune dependencies, enable ASAR, exclude unneeded files, tree-shake, compress assets, mind native modules, and measure the savings.
เรียนรู้ JavaScript ด้วย AI tutor — ฟรี
เขียนและเรียกใช้โค้ดจริงในเบราว์เซอร์ของคุณ รับความช่วยเหลือทันทีจาก AI tutor 24/7 และเรียนรู้ต่อจากที่คุณหยุดบนเว็บหรือในแอป
- คอร์ส
- 12
- บทเรียน
- 47
คำถามที่พบบ่อย
บทเรียน “การลดขนาดแพ็กเกจและพื้นที่ดิสก์” ฟรีหรือไม่
ใช่ — ข้อความเต็มของ “การลดขนาดแพ็กเกจและพื้นที่ดิสก์” ฟรีให้อ่านที่นี่บนเว็บ เพื่อปฏิบัติแบบโต้ตอบ (ตัวแก้ไขโค้ดในตัวและติวเตอร์ AI ตลอด 24/7) และปลดล็อคส่วนที่เหลือของคอร์ส Electron Desktop App Development ให้อัปเกรดเป็น CoddyKit PRO คอร์ส Electron Desktop App Development มีบทเรียนทั้งหมด 4 บทเรียน
คุณจะเรียนรู้อะไรในบทเรียน “การลดขนาดแพ็กเกจและพื้นที่ดิสก์”
ลดขนาดตัวติดตั้งและพื้นที่ดิสก์ของแอป Electron ด้วยการตัดสิ่งที่ต้องพึ่งพาที่ไม่จำเป็น ใช้ ASAR และลบไฟล์ที่ไม่ได้ใช้งาน เพื่อเสริมการเพิ่มประสิทธิภาพเวลาเริ่มต้นและหน่วยความจำ คุณปฏิบัติ Electron Desktop App Development ด้วยโค้ดที่ใช้งานได้จริงที่คุณเรียกใช้โดยตรงในเบราว์เซอร์ และติวเตอร์ AI ตลอด 24/7 ตอบคำถามของคุณขณะที่คุณไปผ่านบทเรียน
คุณต้องมีประสบการณ์ก่อนที่จะเริ่มเรียน Electron Desktop App Development หรือไม่
ไม่จำเป็นต้องมีประสบการณ์มาก่อน Electron Desktop App Development บน CoddyKit ออกแบบมาสำหรับผู้เริ่มต้นไปจนถึงผู้เรียนขั้นสูง คุณสามารถเริ่มต้นที่นี่หรือเริ่มจากตัวแรกและเรียนด้วยความเร็วของคุณเอง นี่คือบทเรียนที่ 4 จากทั้งหมด 4 บทเรียน
บทเรียน “การลดขนาดแพ็กเกจและพื้นที่ดิสก์” ใช้เวลานานแค่ไหน
บทเรียน CoddyKit ส่วนใหญ่ใช้เวลาประมาณ 5–10 นาที แต่ละบทเรียนจึงสั้นและเป็นแบบโต้ตอบ คุณสามารถก้าวหน้าอย่างต่อเนื่องและกลับมาเรียนต่อจากตรงที่เพิ่งหยุดบนเว็บและแอปได้เลย
ฉันเขียนและรันโค้ดในบทเรียน Electron Desktop App Development นี้ได้ไหม
ได้ บทเรียน Electron Desktop App Development ทุกบทมีตัวแก้ไขโค้ดในตัว คุณจึงเขียนและรันโค้ดจริงได้เลยในเบราว์เซอร์ และได้รับข้อเสนอแนะจาก AI ในทันที — ไม่ต้องติดตั้งในเครื่องของคุณ
บทเรียนทั้งหมดในหลักสูตรนี้
- การเพิ่มประสิทธิภาพเวลาเริ่มต้น
- เทคนิคการจัดการหน่วยความจำ
- การวิเคราะห์ประสิทธิภาพ
- การลดขนาดแพ็กเกจและพื้นที่ดิสก์