setup-use-import-maps — Claude Code rule: import maps, not CDN scripts
setup-use-import-maps — a rule that swaps the old Three.js CDN <script src> tag for an import map with ES modules and a pinned version.
MIT ★ 4,719 updated 2026-10-24
.claude/rules/setup-use-import-maps.mdWhat setup-use-import-maps does
The rule covers one thing: how Three.js gets into a page. Instead of a CDN <script src> pointing at three.min.js, the HTML declares <script type="importmap"> and maps three to three.module.js, with a three/addons/ prefix aimed at examples/jsm/. Application code then sits in <script type="module"> and pulls OrbitControls from three/addons/controls/OrbitControls.js.
What the old pattern costs, per the rule: a global THREE, no tree shaking, version clashes, and module resolution that fails. The fix is a single map naming an exact version; the examples use [email protected].
WebGPU has its own map here. three resolves to three.webgpu.js, a three/tsl alias points at three.tsl.js, and three/addons/ stays put. If a project already loads global THREE from r128, the rule means rewriting that wiring, because otherwise the version conflict stays.
What it helps with
- move a project off global
THREEonto ES modules - pin the Three.js version in one place
- load
OrbitControlswithout copying files out ofexamples/jsm/ - find out why tree shaking drops nothing
- set up an import map for the WebGPU build
Example prompts for the agent
- Rewrite the Three.js script tag as an import map, with
threepointing atthree.module.js. - Swap the CDN
three.min.jsinclude for<script type="importmap">and module imports. - Add
three/tslto the import map for the WebGPU build.
How to install setup-use-import-maps
Manually: put the files in place
.claude/rules/setup-use-import-maps.mdThe paths frontmatter field limits the files
AGENTS.md
Codex reads AGENTS.md: paste the rule text there
Manually: put the files in place
.cursor/rules/setup-use-import-maps.mdcFrontmatter: description, globs, alwaysApply
Manually: put the files in place
.github/instructions/setup-use-import-maps.instructions.mdThe applyTo field sets which files it applies to
Manually: put the files in place
.devin/rules/setup-use-import-maps.mdManually: put the files in place
.clinerules/setup-use-import-maps.mdStep by step, with commands for each platform: AGENTS.md vs CLAUDE.md: what they are and which one to use
Questions about setup-use-import-maps
How do I install setup-use-import-maps in Claude Code?
Place the file at .claude/rules/setup-use-import-maps.md. The rule ships as markdown, so copying it into that folder is the whole step.
What does setup-use-import-maps do?
It tells the agent to wire Three.js through an import map with ES modules and a fixed version instead of a CDN script tag.
Why does the rule avoid the CDN <script src> tag?
That tag leaves THREE in the global scope, blocks tree shaking and breaks once two versions meet on one page.
Source text
setup-use-import-maps.md · MIT
# setup-use-import-maps
**Use Import Maps instead of old CDN script tags.**
## Why It Matters
The old CDN pattern (`<script src="...three.min.js">`) is outdated and causes:
- Module resolution issues
- No tree shaking
- Global namespace pollution
- Version conflicts
## Bad Example
```html
<!-- WRONG - Outdated pattern (DO NOT USE) -->
<script src="https://cdnjs.cloudflare.com/ajax/libs/three.js/r128/three.min.js"></script>
<script>
// THREE is global, no modules
const scene = new THREE.Scene();
</script>
```
## Good Example
```html
<!-- CORRECT - Modern Import Maps pattern -->
<script type="importmap">
{
"imports": {
"three": "https://cdn.jsdelivr.net/npm/[email protected]/build/three.module.js",
"three/addons/": "https://cdn.jsdelivr.net/npm/[email protected]/examples/jsm/"
}
}
</script>
<script type="module">
import * as THREE from 'three';
import { OrbitControls } from 'three/addons/controls/OrbitControls.js';
const scene = new THREE.Scene();
</script>
```
## WebGPU Import Map
```html
<script type="importmap">
{
"imports": {
"three": "https://cdn.jsdelivr.net/npm/[email protected]/build/three.webgpu.js",
"three/tsl": "https://cdn.jsdelivr.net/npm/[email protected]/build/three.tsl.js",
"three/addons/": "https://cdn.jsdelivr.net/npm/[email protected]/examples/jsm/"
}
}
</script>
```
## References
- [Three.js Installation Guide](https://threejs.org/manual/#en/installation)
- [MDN Import Maps](https://developer.mozilla.org/en-US/docs/Web/HTML/Element/script/type/importmap)
© zebbern · MIT · zebbern/claude-code-guide