Skip to content

Conversation

@kalwalt
Copy link
Member

@kalwalt kalwalt commented Nov 4, 2025

Configure Vite for ESM-only build, vitest and update dependencies

This PR makes the plugin production‑ready with an ESM‑only Vite build, bundles the module worker and ARToolKit, fixes worker asset paths, updates the example to load from dist, and adds a solid test suite with CI.

Highlights

  • 🚀 ESM‑only build with Vite and relative worker assets (base: './')
  • 📦 Example imports from /dist and no longer needs artoolkitModuleUrl
  • 🧠 Plugin now emits markerFound/markerUpdated/markerLost from getMarker events
  • 🧪 Vitest + coverage + GitHub Actions CI

What changed

  • 🛠 Build and distribution

    • Vite library build (ESM only), worker format set to ES, target esnext
    • base: './' so worker/assets resolve relative to the ESM file (fixes /assets vs /dist/assets)
    • package.json points exports/import to dist/arjs-plugin-artoolkit.esm.js; scripts updated
    • Output artifacts:
      • dist/arjs-plugin-artoolkit.esm.js
      • dist/assets/worker-*.js (rewritten worker)
      • dist/assets/ARToolkit-*.js (bundled ARToolKit)
  • 🧩 Plugin/runtime

    • New detection path: convert getMarker payloads into detections and emit:
      • ar:markerFound (first sighting)
      • ar:markerUpdated (subsequent frames)
      • ar:markerLost (after threshold)
    • Keeps raw ar:getMarker forwarding for debugging
    • Worker readiness tracked (workerReady flag), init watchdog, improved logs
  • 👷 Worker

    • Browser‑focused startup and message wiring
    • Posts ready on load and on init to avoid UI races
    • Simplified to avoid top‑level await and non‑browser paths
  • 📄 Docs

    • README and example docs updated:
      • Use /dist/arjs-plugin-artoolkit.esm.js
      • artoolkitModuleUrl is NOT needed with the dist build
      • Serving notes so /dist resolves correctly
  • 🧹 Repo hygiene

    • .gitignore updated to track the repository root /dist but continue ignoring dist elsewhere
    • Example imports adjusted to absolute path: /dist/arjs-plugin-artoolkit.esm.js
  • ✅ Tests and CI

    • Vitest config (jsdom) with coverage thresholds
    • Tests for lifecycle, event forwarding, loadMarker, lost sweep, and edge cases
    • GitHub Actions CI runs build + coverage on pushes/PRs

Why this is better

  • 🔒 Reliable module worker paths in production builds
  • 🧭 Clear developer experience: just import from dist; no ARToolKit URL plumbing
  • 📈 Tested core behaviors with coverage guards
  • 🧰 Easier debugging via raw ar:getMarker plus high‑level marker events

How to test locally

  1. Build
    • npm install
    • npm run build
  2. Serve from repo

@kalwalt kalwalt self-assigned this Nov 4, 2025
@kalwalt kalwalt marked this pull request as ready for review November 4, 2025 13:17
@kalwalt kalwalt added enhancement New feature or request javascript labels Nov 4, 2025
@kalwalt kalwalt requested a review from Copilot November 4, 2025 14:17
@kalwalt kalwalt added the vitest label Nov 4, 2025
Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copilot encountered an error and was unable to review this pull request. You can try again by re-requesting a review.

@kalwalt kalwalt requested a review from Copilot November 4, 2025 14:39
@kalwalt kalwalt changed the title configure Vite for ESM-only build and update dependencies Configure Vite for ESM-only build, vitest and update dependencies Nov 4, 2025
Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copilot encountered an error and was unable to review this pull request. You can try again by re-requesting a review.

@kalwalt kalwalt merged commit e54ec82 into main Nov 4, 2025
4 checks passed
@kalwalt kalwalt deleted the feature-vite-bundler branch November 4, 2025 15:21
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants