Use static import declarations to load ES modules at parse time for tree-shaking and static analysis
When to Use
You need to import functions, classes, or constants that are always required at startup
You want bundlers (webpack, Vite, Rollup) to tree-shake unused exports
You need static analysis support for IDE auto-imports, type checking, and refactoring
Instructions
Use import { name } from './module.js' at the top of the file for all compile-time dependencies.
Prefer named exports over default exports — they enable tree-shaking and IDE auto-imports.
Group imports: external packages first, then internal modules, then relative paths.
Never use require() in ESM files — static import enables bundler dead-code elimination.
// Named exports — tree-shakeable
import { useState, useEffect } from 'react';
import { formatDate, parseDate } from '../utils/date.js';
// Default export — avoid when possible
import MyComponent from './MyComponent.js';
Use import * as ns from './module.js' sparingly — it imports everything and can defeat tree-shaking.
Details
Static import declarations are resolved at parse time, before any code executes. This enables bundlers to analyze the dependency graph and eliminate unused exports (tree-shaking). Static imports are hoisted — they run before the module body regardless of where they appear in the file.
Trade-offs:
Static imports cannot be conditional — they always load, even if the imported value is rarely used
Circular dependencies between static imports can cause initialization issues (temporal dead zone)
Large static import trees increase initial bundle size and startup time
When NOT to use:
For heavy libraries used only in rare code paths — use dynamic import() instead
For feature-flagged code that should not be loaded unless the flag is enabled
For route-specific code in SPAs — use code splitting with dynamic import
Read the instructions and examples in this document.
Apply the patterns to your implementation, adapting to your specific context.
Verify your implementation against the details and edge cases listed above.
Harness Integration
Type: knowledge — this skill is a reference document, not a procedural workflow.
No tools or state — consumed as context by other skills and agents.
Success Criteria
The patterns described in this document are applied correctly in the implementation.
Edge cases and anti-patterns listed in this document are avoided.
1---2name: js-static-import3description: JS Static Import4---5# JS Static Import67> Use static import declarations to load ES modules at parse time for tree-shaking and static analysis89## When to Use1011- You need to import functions, classes, or constants that are always required at startup12- You want bundlers (webpack, Vite, Rollup) to tree-shake unused exports13- You need static analysis support for IDE auto-imports, type checking, and refactoring1415## Instructions16171. Use `import { name } from './module.js'` at the top of the file for all compile-time dependencies.182. Prefer named exports over default exports — they enable tree-shaking and IDE auto-imports.193. Group imports: external packages first, then internal modules, then relative paths.204. Never use `require()` in ESM files — static `import` enables bundler dead-code elimination.2122```javascript23// Named exports — tree-shakeable24import { useState, useEffect } from 'react';25import { formatDate, parseDate } from '../utils/date.js';2627// Default export — avoid when possible28import MyComponent from './MyComponent.js';29```30315. Use `import * as ns from './module.js'` sparingly — it imports everything and can defeat tree-shaking.3233## Details3435Static `import` declarations are resolved at parse time, before any code executes. This enables bundlers to analyze the dependency graph and eliminate unused exports (tree-shaking). Static imports are hoisted — they run before the module body regardless of where they appear in the file.3637**Trade-offs:**3839- Static imports cannot be conditional — they always load, even if the imported value is rarely used40- Circular dependencies between static imports can cause initialization issues (temporal dead zone)41- Large static import trees increase initial bundle size and startup time4243**When NOT to use:**4445- For heavy libraries used only in rare code paths — use dynamic `import()` instead46- For feature-flagged code that should not be loaded unless the flag is enabled47- For route-specific code in SPAs — use code splitting with dynamic import4849## Source5051https://patterns.dev/javascript/static-import5253## Process54551. Read the instructions and examples in this document.562. Apply the patterns to your implementation, adapting to your specific context.573. Verify your implementation against the details and edge cases listed above.5859## Harness Integration6061- **Type:** knowledge — this skill is a reference document, not a procedural workflow.62- **No tools or state** — consumed as context by other skills and agents.6364## Success Criteria6566- The patterns described in this document are applied correctly in the implementation.67- Edge cases and anti-patterns listed in this document are avoided.
Run npx skillmds@latest add intense-visions/js-static-import in your terminal (requires Node.js), paste this page's agent-chat prompt into Claude, Cursor, or any MCP-connected agent, or download the SKILL.md file and copy it into your agent's skills directory.
JS Static Import It is listed under Coding & Dev Tools on SkillMD.
This skill has not completed SkillMD's automated safety review yet. Independent scanners report: SkillSpector: PASS, Skill Scanner: PASS. Capability flags: makes network calls. SkillMD never runs a skill's scripts for you; review the SKILL.md before installing.
This skill is tagged as working with Claude Code, Claude.ai, OpenAI Codex. SKILL.md is an open format, so most agents that read a skills directory can load it too.
Yes. Installing skills from SkillMD is free, and the skill stays under its author's original license.
Intense-Visions (@intense-visions) published this skill. Their other Agent Skills are listed on their SkillMD profile.