The project was born out of pure interest in using Lightning Web Components outside of the Salesforce platform. I was inspired to the Snake idea by the following blog article and reused some of the game code:
How to Build the Snake Game Using Lightning Web Components
If you are also interested in LWC OSS you can find more info here: https://lwc.dev/
The directory structure looks like this:
src/
βββ assets/ // static assets
β βββ fonts/
β βββ icons/
β βββ images/
β βββ styles/
| βββ favicon.ico
βββ layouts/ // lwc layouts
β βββ main.html
βββ modules/ // lwc modules
βββ snake/
βββ app/
βββ app.css
βββ app.html
βββ app.js
βββ game/
βββ game.css
βββ game.html
βββ game.js
lwr.config.json // lwr configuration
package.json // npm packaging configuration
The LWR server is configured in lwr.config.json
, at the root of the project. It has two LWC module and one server-side route.
{
"lwc": { "modules": [{ "dir": "$rootDir/src/modules" }, { "npm": "lightning-base-components" }] },
"routes": [
{
"id": "snake",
"path": "/",
"rootComponent": "snake/app",
"layoutTemplate": "$layoutsDir/main.html",
"bootstrap": {
"syntheticShadow": true
}
}
],
"assets": [
{
"alias": "assetsDir",
"dir": "$rootDir/src/assets",
"urlPath": "/assets"
},
{
"dir": "$rootDir/src/assets/fonts",
"urlPath": "/fonts"
},
{
"alias": "favicon",
"file": "$rootDir/src/assets/favicon.ico",
"urlPath": "/favicon.ico"
}
]
}
Run Prettier to check all files for formatting issues:
yarn run prettier
Run ESLint to check for linting issues:
yarn run lint
Install all required dependencies:
yarn install
Start the local development server:
yarn dev
Open the site at http://localhost:3000
Build the project:
yarn build
Preview the generated site:
yarn start
Open the site at http://localhost:3000