/swapi

SWAPI Search App with ReactJs and TypeScript Exercise

Primary LanguageTypeScriptCreative Commons Zero v1.0 UniversalCC0-1.0

SWAPI Search App with ReactJs and TypeScript

Codacy Badge

SWAPI Search App with ReactJs and TypeScript.

Resources and referens

Project setup

Clone the repository, then install the dependencies and start the development server.

npm install
npm start

The rest of the commands are available in the package.json file. See also the .github/workflows/workflow.yml file for the GitHub Actions workflow.

Initial setup of project

Install ReactJs and Typescript by Vite

npm create vite@latest
# ✔ Project name: … prj-ts-react-swapi
# ✔ Select a framework: › React
# ✔ Select a variant: › TypeScript
cd prj-ts-react-swapi/
npm install
npm i react-router-dom axios dompurify @types/dompurify
npm i usehooks-ts
npm i @react-hook/media-query
  • Create start command in package.json file as follows:

    "scripts": {
        "start": "vite --host 0.0.0.0 --port 3000",
    }
  • Note I need to access the app from other devices on the same network to test it on Mobile, Hackintosh, Windows etc. This is also very useful option when you are using WSL2, otherwise you may need to export the port manually.

  • Clean the src/ and public/ directories and start working on the project.

Install other packages

npm i --save-dev tailwindcss postcss autoprefixer postcss-import
npx tailwindcss init -p
npm i @tailwindcss/forms @tailwindcss/typography @tailwindcss/aspect-ratio
npm i @headlessui/react
npm i @heroicons/react
npm i react-icons

References:

Setup the Git Repository and Push to GitHub

# git config --global init.defaultBranch master
git init
git add -A
git commit -m "Initial commit"
git branch -M master
git remote add origin git@github.com:metalevel-tech/prj-ts-react-swapi.git
git push -u origin master

Automation with GitHub Actions

Shell helpers

PNG > WebP conversion

FILE="Input_image.png"
convert "$FILE" -quality 80 -strip -define webp:lossless=true -define webp:method=4 "${FILE%.*}_80.webp"
convert "$FILE" -quality 70 -strip -define webp:lossless=false -define webp:method=4 "${FILE%.*}_70.webp"

SVG > ICO conversion

FILE="Input_image.svg"
convert -background transparent "$FILE" -clone 0 -resize 32x32  favicon.ico