playground/README.md
This is the @lit-internal/playground package. Inspired by (and
loosely compatible with) the
Lit.dev playground, it provides
an easy way to spin up small example projects that depend on the
monorepo's packages, for the purpose of testing, exploration,
demonstration, etc.
The monorepo playground is intended to support any use case that benefits from having a live example running in a dev server while working on monorepo packages. For example:
For some use cases, examples may be throw-aways, used during
local development and never committed; the playground includes
a scratch folder for this purpose. For other use cases, it may
be useful to commit examples to the repo, either temporarily or
permanently.
Run the scripts below from the playground directory.
Note:
playground/pp/ for auto-complete, or omit for brevityscratch folder (playground/p/scratch) to
make Git ignore itnpm run new -- my-example
playground/p/my-example') by cloning a minimal templateplayground/pnpm run start -- my-demos/cool-demo
playground/p/my-demos/cool-demo)npm run import -- timer ee310ee9432d7a634852c8b9a56f95a9
playground/p/timer)
by importing from a Gistpackage.json, derived from
the Gist's original package.json (if any) and source filesnpm run export -- my-example
index.html file (if present) will be served if you
browse to the server's localhost port without specifying a path.js extension, regardless of
whether the source file is JavaScript or TypeScript/ or the referring file
./package.json (though the template example
does include an empty package.json for convenience)package.json file and use the npm CLI directly in the example
folder to manage and install dependenciesSince Gists don't support nested folders, you should use a flat structure for any example you might want to export
The Lit.dev playground expects a single HTML entrypoint, at
index.html
The Lit.dev playground supports implicit (undeclared) dependencies, but the monorepo playground does not (with the exception of Lit monorepo packages)
The provided import script constructs a package.json, derived
from the Gist's original package.json (if any) and source files
package.json explicitly depends on any Lit
monorepo packages, these dependencies are omitted from the
constructed package.json so that they will be loaded from the
current monorepo source insteadpackage.json, these packages are added to the
constructed package.json (though only top-level, static
imports are detected)Upon successful completion, the import script writes a file
named _import.info.json to the example folder, containing the
source Gist ID and the contents of the Gist's original
package.json file
The export script requires manual installation of
this gist CLI
The import and export scripts do minimal error detection;
they're designed to "just work" for common cases but don't
enforce compliance with structural requirements and may be
tripped up by edge cases
The @lit-internal/playground package is a workspace within
the monorepo so that its dependencies (TypeScript and Vite)
are installed via npm install at the monorepo root
Individual examples are not workspaces; each example's external dependencies (if any) are installed locally
Examples use the Vite dev server
resolveId hook makes it easier to support seamless
import and export of examples from the Lit.dev playground
(specifically, allowing .ts source files to be loaded from
HTML files using .js file extensions—something that the
Lit.dev playground requires but which isn't supported out of
the box by either Vite or @web/dev-server).@web/dev-server'splayground directory using the provided NPM script