React Starter
Table of Contents
Project Setup
Follow steps to execute this boilerplate.
Install dependencies
$ yarn install
Compiles and hot-reloads for development
$ yarn serve
Compiles and minifies for production
$ yarn build
Lints and fixes files
$ yarn lint
Runs unit tests
Files: src/**/*.spec.js
$ yarn unit
Runs end-to-end tests
Files: e2e/**/*.spec.js
# Before running the `e2e` command, make sure to run the following commands.
$ yarn build
$ yarn preview
# If it's not setup, run it.
$ yarn setup
$ yarn e2e
Measures site's URLs
Files: e2e/**/*.meas.js
# Before running the `meas` command, make sure to run the following commands.
$ yarn build
$ yarn preview
# If it's not setup, run it.
$ yarn setup
$ yarn meas
Mock requests
mock/requests
is a fork of Koa-Starter that was made easy and quick way to run mock APIs locally.
# If it's not active, run it.
$ yarn active
$ yarn mock
Key Features
This seed repository provides the following features:
- ---------- Essentials ----------
- React
- React Router
- React Intl
- Recompose
- Redux
- Redux Thunk
- Reselect
- Material UI
- Axios
- Apollo GraphQL
- ReactiveX
- ---------- Tools ----------
- Webpack
- JSX
- JSS
- Puppeteer
- Babel
- ESLint
- Jest
- ---------- Environments ----------
- Node.js
- Yarn
- Caddy
- Netlify
Dockerization
Dockerize an application.
- Build and run the container in the background
$ docker-compose up -d <SERVICE>
- Run a command in a running container
$ docker-compose exec <SERVICE> <COMMAND>
- Remove the old container before creating the new one
$ docker-compose rm -fs
- Restart up the container in the background
$ docker-compose up -d --build <SERVICE>
- Push images to Docker Cloud
# .gitignore
.DS_Store
node_modules
npm
public
functions
coverage
+ dev.Dockerfile
+ stage.Dockerfile
+ prod.Dockerfile
*.log
$ docker login
$ docker build -f ./tools/<dev|stage|prod>.Dockerfile -t <IMAGE_NAME>:<IMAGE_TAG> .
# checkout
$ docker images
$ docker tag <IMAGE_NAME>:<IMAGE_TAG> <DOCKER_ID_USER>/<IMAGE_NAME>:<IMAGE_TAG>
$ docker push <DOCKER_ID_USER>/<IMAGE_NAME>:<IMAGE_TAG>
# remove
$ docker rmi <REPOSITORY>:<TAG>
# or
$ docker rmi <IMAGE_ID>
- Pull images from Docker Cloud
# docker-compose.yml
<dev|stage|prod>:
- image: <dev|stage|prod>
- build:
- context: .
- dockerfile: ./tools/<dev|stage|prod>.Dockerfile
+ image: <DOCKER_ID_USER>/<IMAGE_NAME>:<IMAGE_TAG>
volumes:
- yarn:/home/node/.cache/yarn
tty: true
Configuration
Project environments
Change to your project.
// .firebaserc
{
"projects": {
"development": "<PROJECT_NAME>",
"staging": "<STAGE_PROJECT_NAME>",
"production": "<PROJECT_NAME>"
}
}
Default environments
Set your local environment variables. (use this.<ENV_NAME> = process.env.<ENV_NAME> || <LOCAL_ENV>;
)
// env.js
function Environments() {
this.NODE_ENV = process.env.NODE_ENV || 'development';
this.PROJECT_NAME = process.env.PROJECT_NAME || '<PROJECT_NAME>';
this.HOST_NAME = process.env.HOST_NAME || '0.0.0.0';
this.SITE_PORT = process.env.SITE_PORT || 8000;
this.SITE_URL = process.env.SITE_URL || `http://${this.HOST_NAME}:${this.SITE_PORT}`;
this.APP_BASE = process.env.APP_BASE || '/';
this.GOOGLE_ANALYTICS = process.env.GOOGLE_ANALYTICS || '<GOOGLE_ANALYTICS>';
this.SENTRY_DSN = process.env.SENTRY_DSN || null;
this.RENDERTRON_URL = process.env.RENDERTRON_URL || null;
}
Deployment environment
Set your deployment environment variables.
# tools/<dev|stage|prod>.Dockerfile
# envs --
ENV SITE_URL <SITE_URL>
ENV FUNC_URL <FUNC_URL>
# -- envs
CI environment
Add environment variables to the CircleCI build.
CODECOV_TOKEN
DOCKER_PASSWORD
DOCKER_USERNAME
FIREBASE_TOKEN
SEO friendly
Enable billing on your Firebase Platform and Google Cloud the project by switching to the Blaze plan.
Serve dynamic content for bots.
// firebase.json
"rewrites": [
{
"source": "**",
- "destination": "/index.html"
+ "function": "app"
}
],
Deploy rendertron instance to Google App Engine.
$ git clone https://github.com/GoogleChrome/rendertron
$ cd rendertron
$ gcloud auth login
$ gcloud app deploy app.yaml --project <RENDERTRON_NAME>
Set your rendertron instance in deployment environment.
# tools/<dev|stage|prod>.Dockerfile
# envs --
ENV RENDERTRON_URL <RENDERTRON_URL>
# -- envs
VS Code settings
The most basic configuration.
{
"window.zoomLevel": 1,
"workbench.colorTheme": "Material Theme",
"workbench.iconTheme": "material-icon-theme",
"eslint.validate": [
"javascript", {
"language": "vue"
},
"javascriptreact",
"html"
],
"javascript.validate.enable": false,
"vetur.validation.script": false
}
Directory Structure
The structure follows the LIFT Guidelines.
.
âââ src
â âââ api
â â âââ __tests__
â â â âââ ...
â â âââ _<THING> -> api of private things
â â â âââ ...
â â âââ core -> core feature module
â â â âââ ...
â â âââ <FEATURE> -> feature modules
â â â âââ __tests__
â â â â âââ ...
â â â âââ _<THING> -> feature of private things
â â â â âââ ...
â â â âââ ...
â â âââ <GROUP> -> module group
â â â âââ <FEATURE> -> feature modules
â â â âââ __tests__
â â â â âââ ...
â â â âââ _<THING> -> feature of private things
â â â â âââ ...
â â â âââ ...
â â âââ graphql
â â â âââ <FEATURE> -> feature modules
â â â â âââ __tests__
â â â â â âââ ...
â â â â âââ _<THING> -> feature of private things
â â â â â âââ ...
â â â â âââ ...
â â â âââ <GROUP> -> module group
â â â âââ <FEATURE> -> feature modules
â â â âââ __tests__
â â â â âââ ...
â â â âââ _<THING> -> feature of private things
â â â â âââ ...
â â â âââ ...
â â âââ shared -> shared feature module
â â â âââ ...
â â âââ index.js
â âââ app
â â âââ __tests__
â â â âââ ...
â â âââ _<THING> -> app of private things
â â â âââ ...
â â âââ core -> core feature module
â â â âââ ...
â â âââ <FEATURE> -> feature modules
â â â âââ __tests__
â â â â âââ actions.spec.js
â â â â âââ <FEATURE>.e2e-spec.js
â â â â âââ <FEATURE>.spec.js
â â â â âââ <epics|sagas>.spec.js
â â â â âââ reducer.spec.js
â â â â âââ selectors.spec.js
â â â âââ _<THING> -> feature of private things
â â â â âââ ...
â â â âââ actions.js
â â â âââ constants.js
â â â âââ <FEATURE>.vue
â â â âââ <epics|sagas>.js
â â â âââ reducer.js
â â â âââ selectors.js
â â â âââ types.js
â â âââ <GROUP> -> module group
â â â âââ <FEATURE> -> feature modules
â â â âââ __tests__
â â â â âââ actions.spec.js
â â â â âââ <FEATURE>.e2e-spec.js
â â â â âââ <FEATURE>.spec.js
â â â â âââ <epics|sagas>.spec.js
â â â â âââ reducer.spec.js
â â â â âââ selectors.spec.js
â â â âââ _<THING> -> feature of private things
â â â â âââ ...
â â â âââ actions.js
â â â âââ constants.js
â â â âââ <FEATURE>.js
â â â âââ <epics|sagas>.js
â â â âââ reducer.js
â â â âââ selectors.js
â â â âââ types.js
â â âââ shared -> shared feature module
â â â âââ ...
â â âââ actions.js
â â âââ App.js
â â âââ constants.js
â â âââ epics.js
â â âââ reducer.js
â â âââ sagas.js
â â âââ selectors.js
â â âââ types.js
â âââ assets -> datas, fonts, images, medias
â â âââ ...
â âââ client.js
â âââ index.html
â âââ server.js
âââ tools
â âââ ...
âââ .babelrc
âââ .editorconfig
âââ .eslintrc
âââ .firebaserc
âââ .flowconfig
âââ .gitignore
âââ Dockerfile
âââ LICENSE
âââ README.md
âââ circle.yml
âââ docker-compose.yml
âââ env.js
âââ firebase.json
âââ jest.config.js
âââ package.json
âââ webpack.config.js
âââ yarn.lock