# Installation

> Install @gamepadly/sdk from npm or load it from a CDN in a single HTML file with no build step. Zero runtime dependencies, ESM with TypeScript types, and a measured size for every entry point.

Source: https://gamepadly.com/sdk/start/installation

## npm

```bash
npm install @gamepadly/sdk
# or: pnpm add @gamepadly/sdk / yarn add @gamepadly/sdk / bun add @gamepadly/sdk
```

The package is ESM only, ships TypeScript types, and has **no runtime dependencies**. Each feature is a separate
entry point, so your bundle only contains what you import. Sizes below are what each import adds to a minified,
gzipped bundle, measured from the source on every docs build:

| Import | Use it for | Size (gzip) |
| :--- | :--- | ---: |
| `@gamepadly/sdk` | The hub: players, input, action maps, haptics, triggers, lightbar, motion, touchpad | 17.2 KB |
| `@gamepadly/sdk/bridge` | Driving an existing keyboard and mouse game with a controller (size includes the hub) | 19.6 KB |
| `@gamepadly/sdk/game` | Mock controllers for tests, the portable game contract and a reference host | 4 KB |
| `@gamepadly/sdk/loop` | A fixed-step game loop, a DPR-aware canvas stage, and disposables | 0.5 KB |
| `@gamepadly/sdk/diagnostics` | Building your own controller tester (circularity, drift, bounce) | 2.6 KB |
| `@gamepadly/sdk/audio` | Sample playback and routing on any `AudioContext` | 1.9 KB |
| `@gamepadly/sdk/mic` | Microphone blow detection and level metering | 1.7 KB |
| `@gamepadly/sdk/link` | Optional DualSense speaker and 4-channel audio | 9.5 KB |
| `@gamepadly/sdk/browser` | Everything above as one ESM file, for CDN use | 43.2 KB |

## A single HTML file, no build step

Load the browser build from a CDN inside a module script:

```html
<script type="module">
  import { createGamepadly, createKeyMouseBridge } from 'https://esm.sh/@gamepadly/sdk@0.9.0/browser';

  const hub = createGamepadly();
  // ...
</script>
```

Pin the version in the URL so a future release cannot change your page. Every [example](https://gamepadly.com/sdk/examples) is one
HTML file written this way.

## Server-side rendering

Importing the SDK and calling `createGamepadly()` is safe on the server (Next.js, Nuxt, Astro, SvelteKit): it
reports no controller and does nothing. Controllers only appear in the browser, so create the hub in client code,
for example in a React `useEffect`.

## Browser requirements

- **Secure context.** The Gamepad API and WebHID only work over HTTPS or on `localhost`.
- **A button press first.** Browsers hide connected controllers until the player presses a button on the page.
  Show a "Press any button" hint until `p1.input.getState().connected` is true.
- **A click for WebHID.** `hub.connectWebHID()` opens the browser's device picker, so call it from a click
  handler, never on page load. WebHID is available in desktop Chrome and Edge.

See [Compatibility](https://gamepadly.com/sdk/compatibility) for which browsers, systems and controllers have been verified.
