static-import — скилл для Claude Code: статический импорт ES2015
Объясняет синтаксис import в ES2015 и помогает решить, когда модуль стоит грузить сразу, а когда переключиться на динамический импорт.
npx skills add PatternsDev/skills --skill static-import -a claude-codeЧто делает static-import
Скилл разбирает статический импорт на примере чат-приложения: компонент Chat подтягивает UserProfile, ChatList и ChatInput, а внутри ChatInput так же подключён EmojiPicker. Все эти модули попадают в начальный бандл, и движок выполняет их сразу, как только доходит до строки с import.
Отсюда и главный риск: в примере сборка Webpack складывает код в один main.bundle.js размером 1.5 MiB. Пока App не загрузит и не разберёт все модули, он ничего не покажет на экране. Если у пользователя слабое устройство или медленная сеть, это заметно. EmojiPicker нужен только после клика по эмодзи — его логичнее грузить динамически.
Скилл срабатывает на файлах **/*.js и **/*.ts, так что в проекте с TypeScript он тоже применится. Рядом лежат родственные скиллы module-pattern и singleton-pattern.
Какие задачи решает
- понять, какие модули уходят в начальный бандл
- отличить статический импорт от динамического
- найти компонент, который грузится зря при старте
- объяснить, когда движок выполняет импортированный модуль
- решить, что перевести на динамический импорт
Примеры запросов агенту
- покажи, какие модули в этом файле попадают в начальный бандл
- почему
EmojiPickerгрузится сразу, хотя нужен только по клику - перепиши статические импорты
ChatInputна динамические
Как установить static-import
1Через Skills CLI (Vercel)
npx skills add PatternsDev/skills --skill static-import -a claude-code2Вручную: положить файлы
~/.claude/skills/static-import/SKILL.mdПапка скилла целиком; для одного проекта — .claude/skills/static-import/
1Через Skills CLI (Vercel)
npx skills add PatternsDev/skills --skill static-import -a codex2Вручную: положить файлы
.agents/skills/static-import/SKILL.mdДля всех проектов — ~/.agents/skills/
1Через Skills CLI (Vercel)
npx skills add PatternsDev/skills --skill static-import -a cursor2Вручную: положить файлы
.cursor/skills/static-import/SKILL.mdCursor читает и .agents/skills/, и .claude/skills/
1GitHub CLI
gh skill install PatternsDev/skills static-import2Вручную: положить файлы
.github/skills/static-import/SKILL.md1Через Skills CLI (Vercel)
npx skills add PatternsDev/skills --skill static-import -a gemini-cli2Командой платформы
gemini skills install https://github.com/PatternsDev/skills --path javascript/static-importВручную: положить файлы
.devin/skills/static-import/SKILL.mdСтарый путь .windsurf/skills/ тоже читается
Через Skills CLI (Vercel)
npx skills add PatternsDev/skills --skill static-import -a opencodeClaude.ai
Упакуйте папку в zip и загрузите в Settings → Capabilities → Skills
По шагам, с командами для каждой платформы: Как установить скилл в Claude Code: пять способов
Вопросы о static-import
Как установить static-import в Claude?
Выполните npx skills add PatternsDev/skills --skill static-import -a claude-code. После этого файл скилла лежит в ~/.claude/skills/static-import/SKILL.md.
Что делает static-import?
Учит синтаксису статического импорта ES2015 и объясняет, что все такие модули попадают в начальный бандл. Помогает понять, когда их лучше заменить динамическим импортом.
На каких файлах работает скилл?
Он привязан к путям **/*.js и **/*.ts, поэтому подхватывается и в JavaScript-, и в TypeScript-проектах.
Исходный текст
SKILL.md · MIT
--- name: static-import description: Teaches static ES2015 import syntax for module dependencies. Use when you need to import code that is required at load time and benefits from static analysis and tree shaking. paths: - "**/*.js" - "**/*.ts" license: MIT metadata: author: patterns.dev version: "1.1" related_skills: - "module-pattern" - "singleton-pattern" --- # Static Import The `import` keyword allows us to import code that has been exported by another module. By default, all modules we're _statically importing_ get added to the initial bundle. A module that is imported by using the default ES2015 import syntax, `import module from 'module'`, is statically imported. Let's look at an example! A simple chat app contains a `Chat` component, in which we're statically importing and rendering three components: `UserProfile`, a `ChatList`, and a `ChatInput` to type and send messages! Within the `ChatInput` module, we're statically importing an `EmojiPicker` component to be able to show the user the emoji picker when the user toggles the emoji. ## When to Use - Use this for importing modules that are needed immediately on page load - This is the default import mechanism — understand it to know when to switch to dynamic imports ## Instructions - Use static imports for modules critical to the initial render - Be aware that all statically imported modules are bundled into the initial bundle - Consider switching to dynamic imports for modules not needed on initial render ## Details The modules get executed as soon as the engine reaches the line on which we import them. Since the components were statically imported, Webpack bundled the modules into the initial bundle: ```bash Asset Size Chunks Chunk Names main.bundle.js 1.5 MiB main [emitted] main ``` Our chat application's source code gets bundled into one bundle: `main.bundle.js`. A large bundle size can affect the loading time of our application significantly depending on the user's device and network connection. Before the `App` component is able to render its contents to the user's screen, it first has to load and parse all modules. Luckily, there are many ways to speed up the loading time! We don't always have to import all modules at once: maybe there are some modules that should only get rendered based on user interaction, like the `EmojiPicker` in this case, or rendered further down the page. Instead of importing all component statically, we can _dynamically_ import the modules after the `App` component has rendered its contents and the user is able to interact with our application. ## Source - [patterns.dev/vanilla/static-import](https://patterns.dev/vanilla/static-import)
© patterns.dev · MIT · PatternsDev/skills