Chuyển đến nội dung
Skillpedia
Lập trình chung75k · #2836

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.md

Sao 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

Hãy dùng skill này để giúp tôi: https://github.com/thedaviddias/Front-End-Checklist/blob/main/skills/es-modules/SKILL.md Đọc tệp SKILL.md tại liên kết đó và làm theo hướng dẫn cho việc của tôi.
Bạn muốn AI tự tìm những skill như thế này?Cài MCP Skillpedia miễn phí: chỉ một dòng, và AI sẽ tìm trong 15.000+ skill trước mỗi việc.Cài đặt trong 1 phút →

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.

repo: thedaviddias/Front-End-Checklist

Độ 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

Skill này có hữu ích không?

0

Đăng nhập để bình chọn.

Bình luận

  • …

Thêm skill từ kho mã này

Skill tương tự