static-import — Claude Code skill: ES2015 static imports
Walks through ES2015 import syntax and helps you decide which modules belong in the initial bundle and which should load on demand.
npx skills add PatternsDev/skills --skill static-import -a claude-codeWhat static-import does
The skill works through a chat app: a Chat component statically imports UserProfile, ChatList and ChatInput, and ChatInput pulls in EmojiPicker the same way. Every one of those modules lands in the initial bundle, and the engine runs a module as soon as it reaches the import line.
That is where the cost shows up. In the example Webpack bundles everything into a single main.bundle.js at 1.5 MiB. The App component has to load and parse all of it before it renders anything, which hurts on a slow connection or an older device. EmojiPicker only appears after a click, so it is a candidate for a dynamic import instead.
The skill triggers on **/*.js and **/*.ts, so it applies to TypeScript projects too. Two related skills sit alongside it: module-pattern and singleton-pattern.
What it helps with
- see which modules end up in the initial bundle
- tell a static import from a dynamic one
- spot a component that loads before it is needed
- explain when an imported module actually executes
- pick what to move to a dynamic import
Example prompts for the agent
- list the modules in this file that go into the initial bundle
- why does
EmojiPickerload up front when it is only needed on click - rewrite the static
ChatInputimports as dynamic ones
How to install static-import
1Skills CLI (Vercel)
npx skills add PatternsDev/skills --skill static-import -a claude-code2Manually: put the files in place
~/.claude/skills/static-import/SKILL.mdCopy the whole skill folder; for one project use .claude/skills/static-import/
1Skills CLI (Vercel)
npx skills add PatternsDev/skills --skill static-import -a codex2Manually: put the files in place
.agents/skills/static-import/SKILL.mdFor all projects use ~/.agents/skills/
1Skills CLI (Vercel)
npx skills add PatternsDev/skills --skill static-import -a cursor2Manually: put the files in place
.cursor/skills/static-import/SKILL.mdCursor also reads .agents/skills/ and .claude/skills/
1GitHub CLI
gh skill install PatternsDev/skills static-import2Manually: put the files in place
.github/skills/static-import/SKILL.md1Skills CLI (Vercel)
npx skills add PatternsDev/skills --skill static-import -a gemini-cli2Platform CLI
gemini skills install https://github.com/PatternsDev/skills --path javascript/static-importManually: put the files in place
.devin/skills/static-import/SKILL.mdThe legacy .windsurf/skills/ path still works
Skills CLI (Vercel)
npx skills add PatternsDev/skills --skill static-import -a opencodeClaude.ai
Zip the folder and upload it in Settings → Capabilities → Skills
Step by step, with commands for each platform: How to install skills in Claude Code: five ways
Questions about static-import
How do I install static-import in Claude?
Run npx skills add PatternsDev/skills --skill static-import -a claude-code. The skill file then sits at ~/.claude/skills/static-import/SKILL.md.
What does static-import do?
It teaches ES2015 static import syntax and makes clear that every statically imported module joins the initial bundle. It also points out when a dynamic import fits better.
Which files does the skill apply to?
It is scoped to **/*.js and **/*.ts, so it picks up in both JavaScript and TypeScript projects.
Source text
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