es-modules
Skill này làm gì
Skill này rà soát các file JavaScript dùng cú pháp module cũ và gợi ý chuẩn hiện đại. Skill dành cho lập trình viên muốn mã gọn hơn và rõ ràng hơn.
Khi nào nên dùng
- ✓Khi các file JavaScript của bạn vẫn dùng require() hoặc module.exports.
- ✓Khi bundle của bạn chứa mã mà bạn không bao giờ dùng.
- ✓Khi bạn muốn các script được tải như module gốc của trình duyệt.
Liên kết skill
https://github.com/thedaviddias/Front-End-Checklist/blob/main/skills/es-modules/SKILL.mdSao chép rồi dán vào AI của bạn (Claude, ChatGPT hoặc Cursor) và nhờ nó làm theo hướng dẫn.
Cách dùng
Cách dễ nhất: sao chép tin nhắn và dán vào AI của bạn. AI sẽ đọc skill và làm theo hướng dẫn.
Tin nhắn có sẵn để dán
Dành cho Claude Code, Codex hoặc Cursor: chạy lệnh trong thư mục dự án của bạn và skill sẽ được cài đặt.
Tải tệp SKILL.md về và thả vào thư mục skill của agent.
Ví dụ cách nhờ AI
“Bạn có thể chuyển các câu lệnh require trong file JavaScript của tôi sang cú pháp import không?”
5 skill mới mỗi tuần. Đọc chỉ 1 phút.
Cách hoạt động
Agent tìm các dòng require và module.exports rồi gợi ý các câu lệnh import và export tương ứng. Agent cũng khuyên dùng named export ở những chỗ phù hợp.
Nội dung kỹ thuật (SKILL.md gốc)
Lấy nguyên văn từ GitHub, do tác giả viết bằng tiếng Anh.
Use ES modules (import/export)
ES modules are statically analyzable — bundlers can determine at build time what code is actually used and eliminate the rest (tree-shaking). CommonJS require() is dynamic and prevents this optimization. ES modules are also the browser-native standard, reducing the need for build-time transformation.
Quick Reference
- Use import/export syntax instead of require()/module.exports
- Named exports improve IDE autocompletion and enable tree-shaking
- Add type="module" to script tags or use a bundler to load ES modules in browsers
- Default exports are fine but named exports scale better in large codebases
Check
Identify any use of require(), module.exports, or exports in this JavaScript file that should be converted to ES module syntax.
Fix
Convert all require() and module.exports statements to ES module import/export syntax.
Explain
Explain the benefits of ES modules over CommonJS, including tree-shaking, static analysis, and browser support.
Code Review
Review scripts, client components, and browser execution paths related to Use ES modules (import/export). Flag exact imports, event handlers, runtime side effects, or blocking operations that violate the rule, and state how the change should be verified in the browser.
For full implementation details, code examples, and framework-specific guidance,
see references/rule.md.
Rule page: https://frontendchecklist.io/rules/javascript/es-modules
Câu hỏi thường gặp
Tree-shaking là gì?
Đó là khi một bundler loại bỏ mã không bao giờ được dùng, làm file nhỏ hơn. Cú pháp module hiện đại giúp việc này khả thi.
Có nên dùng named export không?
Skill nói named export mở rộng tốt hơn trong các codebase lớn, dù default export vẫn ổn.
Làm sao để tải module trong trình duyệt?
Skill gợi ý thêm type=module vào thẻ script, hoặc dùng một bundler.
Chi tiết
Mô tả gốc của tác giả
Use when reviewing scripts, client components, bundles, or runtime behavior related to Use ES modules (import/export). Inspect both source code and the browser execution path so fixes target the real bottleneck or bug.
Độ phổ biến
- Sao GitHub
- 75k
- Vị trí xếp hạng
- #2836
- Giấy phép
- MIT
- Cập nhật
- 31/10/2026
Bình luận
- …
Thêm skill từ kho mã này
frontendchecklist
75kKiểm tra mã frontend và trang trực tiếp theo hơn 380 quy tắc về khả năng tiếp cận, tốc độ, SEO và bảo mật, bằng một công cụ dòng lệnh.
frontend-checklist-global
75kKiểm toán một dự án frontend theo đủ 386 quy tắc của Front-End Checklist, và đưa cách sửa cụ thể cho từng vấn đề tìm thấy.
404-page
75kKiểm tra xem trang báo thiếu của bạn có đưa ra các liên kết hữu ích và trả về mã trạng thái 404 thật hay không, để giúp khách bị lạc tìm đường.
about-page
75kKiểm tra xem trang web có trang Giới thiệu rõ ràng giải thích ai điều hành nó hay không, để xây dựng niềm tin với khách và công cụ tìm kiếm.
Skill tương tự
diffs
394kGiúp agent của bạn tạo một diff có thể chia sẻ về các chỉnh sửa, dưới dạng liên kết xem hoặc file ảnh, thay vì một bản tóm tắt viết tay.
coding-agent
394kGiúp agent của bạn giao một việc lập trình lớn cho Codex, Claude Code hoặc OpenCode chạy nền, rồi theo dõi tiến độ của nó.
gh-issues
394kGiúp agent của bạn tìm issue trên GitHub, chọn những issue cần xử lý và mở pull request với bản sửa, kể cả theo dõi nhận xét đánh giá.