This is an experimental starter kit for a React static app.
- React Router
- CSS Modules + PostCSS + PurgeCSS + StyleLint
- TypeScript + Babel + ESLint
- Jest/React Testing Library for unit testing
- Playwright for E2E testing
- webpack
- Custom i18n solution using
sprintf-js
- Cached fetch responses
- Web workers
- CI/CD workflows with GitHub Actions
- Code quality analysis with SonarQube
# Install dependencies
$ npm install
# Run in dev
$ npm run dev
# Run tests
$ npm test
# Run tests in specific dir relative to src
$ npm test --files=dir
# Build for prod
$ npm run build
# Analyzes the size the generated bundle(s) and displays a visual report in the default browser
$ npm run build --analyze
# Builds the app but skips all HTML/CSS/JS compressions
$ npm run build --raw
See scripts
in package.json
for additional commands.
To prerender this app, you can use react-snap
:
- Install
react-snap
:$ npm install react-snap --save-dev
- Add a
postbuild
script topackage.json
:// package.json { ... "scripts": { ... "postbuild": "react-snap", ... } ... }
- Add the following to
package.json
, note that you must include the root route of every locale forreact-snap
to prerender its subroutes since they're dynamically generated:// package.json { ... "reactSnap": { "source": "build", "include": [ "/404.html", "/ja", ... // Include the root route of all locales ], "puppeteerArgs": [ "--no-sandbox", "--disable-setuid-sandbox" ], "skipThirdPartyRequests": true } ... }
- Ensure that Puppeteer is installed when running CI/CD workflows:
# .github/workflows/job-build.yml ... jobs: default: ... steps: - name: Install APT dependencies for Puppeteer run: apt-get update && apt-get install -yq gconf-service libasound2 libatk1.0-0 libatk-bridge2.0-0 libc6 libcairo2 libcups2 libdbus-1-3 libexpat1 libfontconfig1 libgcc1 libgconf-2-4 libgdk-pixbuf2.0-0 libglib2.0-0 libgtk-3-0 libnspr4 libpango-1.0-0 libpangocairo-1.0-0 libstdc++6 libx11-6 libx11-xcb1 libxcb1 libxcomposite1 libxcursor1 libxdamage1 libxext6 libxfixes3 libxi6 libxrandr2 libxrender1 libxss1 ca-certificates fonts-liberation libappindicator1 libnss3 lsb-release xdg-utils wget ... ... ... ...
When using react-static-starter-kit
as a template, follow these steps to strip placeholder content:
- Replace
LICENSE
file - Edit
README.md
- Edit fields in
package.json
- Edit fields in
config/build.args.ts
- Edit resources in
res/
, then ensure to replace the generated assets insrc/static/
- Edit files in
src/ui/
- Edit translations in
src/locales/
- Moved boilerplate code to
lib/
- Replaced
react-helmet-async
with custom solution inlib/
- Restructured folders
- Decoupled boilerplate architectural code to
src/base
- Removed styled-components in favor of CSS modules
- Removed Redux in favor of Context API
- Removed
react-snap
- Updated how assets are imported
- Relocated
locales
directory - Created reusable workflows for CI/CD
- Added
http-server
forstart
command - Added interactors
- Added
I18nProvider