TypeScript library to manage PS4/PS5 controllers in the browser using WebHID and the Gamepad API.
-
Hot reload development:
- Run
yarn dev:demoto start Vite with hot reload and open the demo (demo/index.dev.html). - The demo imports the library source directly, so any changes in
src/web-dualshock.tsare reflected instantly.
- Run
-
Production build and deploy:
- Run
yarn buildto build the library intodist/. - Run
yarn prepare:demoto copy the build intodemo/distand set updemo/index.htmlfor production (copied fromindex.prod.html). - Run
yarn preview:demoto serve the production demo with the bundled library. - Run
yarn deployto build, prepare, and deploy the demo (with the library) to GitHub Pages. The workflow ensuresindex.htmlis always correct for GitHub Pages.
- Run
yarn dev:demo: Hot reload development demo (source import).yarn build: Builds the library intodist/.yarn prepare:demo: Copiesdist/intodemo/and sets upindex.htmlfor production.yarn preview:demo: Serves the production demo with the built library included.yarn deploy: Builds, prepares, and deploys the demo (with library) to GitHub Pages.
src/web-dualshock.ts: Library source code.src/webhid.d.ts: WebHID type definitions (for compatibility).demo/index.dev.html: Demo for hot reload development (imports source).demo/index.prod.html: Demo for production (uses UMD bundle).demo/index.html: Generated for deploy (copied fromindex.prod.html).dist/: Library build output (ESM and UMD bundles).
The workflow .github/workflows/gh-pages.yml automatically publishes the demo and the library to GitHub Pages on every push to main.
- The project is ready for VS Code and PnP.
- If you have type issues, run
yarn dlx @yarnpkg/sdks vscode.
Inspired by madgooselabs/WebHID-DS4, but using Vite and no Vue.