index: demos
To use a given basic-demo as a template for a new
myproject:
$ npx degit pmndrs/examples/demos/basic-demo myproject
$ code myprojectPrerequisites:
-
Install nvm, then:
$ nvm install $ nvm use $ node -v # make sure your version satisfies package.json#engines.nodenb: if you want this node version to be your default nvm's one:
nvm alias default node -
$ corepack enable $ corepack prepare --activate # it reads "packageManager" $ pnpm -v # make sure your version satisfies package.json#engines.pnpm
$ pnpm install$ pnpm run dev$ pnpm run buildThen pnpm run start.
Details
This will:
- execute
^build2which willvite buildeachdemos/*with:
- a
--baseset to${BASE_PATH}/${app_name} - a custom vite
--config, whith amonkey()plugin that will:deterministicscript intosrc/index.jsx- monkeypatch the
<Canvas>withCheesyCanvasfor setting up the scene for playwright screenshots
- build the Next.js
apps/website - copy final result into
outfolder
[!TIP] This is totally fine
BASE_PATH/BASE_URLto be unset/empty. But for debug purposes(to be 1:1 with GitHub pages) you can:$ BASE_PATH=/examples BASE_URL=http://localhost:4000 npm run build $ npx serve out -p 4000
Important
Testing is WIP
$ pnpm testTo update the snapshots: pnpm test -- -- --update-snapshots
Details
You can also:
$ BASE_PATH=/examples pnpm testFor generating reproductible snapshots, we use
mcr.microsoft.com/playwright:v1.45.3-jammy
Docker image.
$ docker run -it --rm \
-w /app -v "$(pwd)":/app -v /app/node_modules \
mcr.microsoft.com/playwright:v1.45.3-jammy /bin/sh
#
# echo "Hey, I am acting like the CI"
#
# corepack enable && pnpm install --frozen-lockfile
# pnpm testor in one command to update snapshots:
docker run --rm \
-w /app -v "$(pwd)":/app -v /app/node_modules \
mcr.microsoft.com/playwright:v1.45.3-jammy /bin/sh -c "corepack enable && pnpm install --frozen-lockfile && pnpm test -- -- --update-snapshots"