es-modules
它能做什么
这项技能检查使用旧模块语法的 JavaScript 文件,并建议改用现代标准。适用于希望代码更精简、更清晰的开发者。
适用场景
- ✓当你的 JavaScript 文件仍在使用 require() 或 module.exports 的时候。
- ✓当你的打包结果中包含你从未使用的代码的时候。
- ✓当你希望脚本作为原生浏览器模块加载的时候。
技能链接
https://github.com/thedaviddias/Front-End-Checklist/blob/main/skills/es-modules/SKILL.md复制后粘贴给你的 AI(Claude、ChatGPT 或 Cursor),让它按照说明操作。
使用方法
最简单的方法:复制下面的消息,粘贴给你的 AI。它会读取这个技能并按说明操作。
可直接粘贴的消息
适用于 Claude Code、Codex 或 Cursor:在项目文件夹中运行,即可安装该技能。
下载 SKILL.md,放进智能体的技能文件夹。
可以这样问 AI
“请把我 JavaScript 文件中的 require 语句转换为 import 语法。”
每周 5 个新技能,1 分钟读完。
工作原理
智能体会找出 require 和 module.exports 的行,并建议对应的 import 和 export 语句。在合适的地方,它还会推荐具名导出。
技术内容(原始 SKILL.md)
作者在 GitHub 上的英文原文。
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
常见问题
什么是 tree-shaking?
它是指打包工具移除从未被使用的代码,从而使文件变小。现代模块语法使这一点成为可能。
我应该使用具名导出吗?
这项技能说明,具名导出在大型代码库中更易扩展,不过默认导出仍然可以使用。
如何在浏览器中加载模块?
这项技能建议在 script 标签上添加 type=module,或使用打包工具。
详情
作者的原始描述
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.
热度
- GitHub 星标
- 75k
- 排名
- #2836
- 许可证
- MIT
- 更新时间
- 2026/10/31
评论
- …
同一仓库的更多技能
frontendchecklist
75k使用命令行工具,依据 380 多条关于无障碍、速度、SEO 和安全的规则,检查前端代码和线上页面。
frontend-checklist-global
75k依据全部 386 条 Front-End Checklist 规则审查前端项目,并为发现的每个问题给出具体修复方法。
404-page
75k检查你的页面缺失提示是否提供有用的链接,并返回真正的 404 状态,帮助迷路的访客找到方向。
about-page
75k审查你的网站是否有清晰的关于页面,说明由谁运营,以建立访客和搜索引擎的信任。