Skip to main content
rule CX Codex

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

Install into Claude Code · Manually: put the files in place All methods and platforms ↓
.claude/rules/setup-use-import-maps.md
Open on GitHub

What 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 THREE onto ES modules
  • pin the Three.js version in one place
  • load OrbitControls without copying files out of examples/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 three pointing at three.module.js.
  • Swap the CDN three.min.js include for <script type="importmap"> and module imports.
  • Add three/tsl to 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.md

The paths frontmatter field limits the files

Step 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

Similar IDE rules

All IDE rules for Frontend and UI →

From the same set86

The whole set →
server-auth-actions The server-auth-actions rule puts authentication and permission checks inside every Server Action. Use it to guard server mutations that callers can invoke directly. CX Codex +1 ★ 4,719repo stars render-delta-time render-delta-time instructs agents to use delta time in animation loops so motion remains consistent across all display refresh rates. CX Codex +1 ★ 4,719repo stars memory-dispose-geometry memory-dispose-geometry is a Claude Code rule that tells the agent to release geometry when removing scene objects. It applies to Three.js resource cleanup. CX Codex +1 ★ 4,719repo stars root-cause-debugger The root-cause-debugger subagent for Claude Code and Codex reproduces failures and finds bug root causes before code changes. It helps diagnose bugs without editing code. CX Codex ★ 4,719repo stars code-reviewer code-reviewer is a Claude Code subagent that checks completed work for bugs and regressions. It runs after implementation or when an existing diff needs review. CX Codex ★ 4,719repo stars perf-visibility-toggle perf-visibility-toggle guides the AI to toggle the visible prop on Three.js components rather than conditionally unmounting them, avoiding GPU shader recompilation. CX Codex +1 ★ 4,719repo stars perf-r3f-perf The perf-r3f-perf rule teaches Claude Code about r3f-perf, a performance monitoring library for Three.js scenes in real time. Spot frame drops, memory leaks, and unnecessary matrix recalculations as they happen. CX Codex +1 ★ 4,719repo stars codebase-mapper codebase-mapper maps repository structure, call chains, and data flows before code changes without mutating any files. CX Codex ★ 4,719repo stars

More in the catalog

Project sponsors

Companies that keep this analytics open