├── .dockerignore ├── .env ├── .eslintignore ├── .eslintrc.json ├── .gitignore ├── .husky ├── pre-commit └── pre-push ├── .lintstagedrc.json ├── .nvmrc ├── .prettierignore ├── .prettierrc.json ├── .stylelintignore ├── .stylelintrc.json ├── Dockerfile ├── LICENSE ├── README.md ├── docker-compose.yml ├── index.html ├── package-lock.json ├── package.json ├── src ├── client │ ├── App.jsx │ ├── App.module.css │ ├── components │ │ ├── Button │ │ │ ├── Button.jsx │ │ │ └── Button.module.css │ │ └── Welcome │ │ │ ├── Welcome.jsx │ │ │ └── Welcome.module.css │ ├── favicon.svg │ ├── globals.css │ ├── logo.svg │ └── main.jsx └── server │ ├── index.js │ └── lib │ └── router.js └── vite.config.js /.dockerignore: -------------------------------------------------------------------------------- 1 | # config files 2 | .github/ 3 | .husky/ 4 | .jest/ 5 | .vscode/ 6 | .editorconfig 7 | .eslintrc 8 | .git 9 | .gitignore 10 | .prettierignore 11 | .prettierrc 12 | .releaserc 13 | Dockerfile 14 | docker-compose.yml 15 | Jenkinsfile 16 | jest.config.js 17 | 18 | # documentation 19 | LICENSE 20 | CHANGELOG.md 21 | README.md 22 | 23 | # build files 24 | node_modules/ 25 | -------------------------------------------------------------------------------- /.env: -------------------------------------------------------------------------------- 1 | VITE_SVG_PATH='/public/generated' 2 | PORT=3001 3 | -------------------------------------------------------------------------------- /.eslintignore: -------------------------------------------------------------------------------- 1 | node_modules 2 | .DS_Store 3 | dist 4 | dist-ssr 5 | *.local 6 | .eslintcache -------------------------------------------------------------------------------- /.eslintrc.json: -------------------------------------------------------------------------------- 1 | { 2 | "env": { 3 | "browser": true, 4 | "es2021": true, 5 | "node": true 6 | }, 7 | "extends": ["eslint:recommended", "prettier", "plugin:react/recommended"], 8 | "parser": "babel-eslint", 9 | "parserOptions": { 10 | "ecmaVersion": 12, 11 | "sourceType": "module" 12 | }, 13 | "plugins": ["react-hooks"], 14 | "rules": {}, 15 | "settings": { 16 | "react": { 17 | "version": "17.0" 18 | } 19 | } 20 | } 21 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | node_modules 2 | .DS_Store 3 | dist 4 | dist-ssr 5 | *.local 6 | .eslintcache -------------------------------------------------------------------------------- /.husky/pre-commit: -------------------------------------------------------------------------------- 1 | #!/bin/sh 2 | . "$(dirname "$0")/_/husky.sh" 3 | 4 | npx lint-staged --config .lintstagedrc.json 5 | -------------------------------------------------------------------------------- /.husky/pre-push: -------------------------------------------------------------------------------- 1 | #!/bin/sh 2 | . "$(dirname "$0")/_/husky.sh" 3 | 4 | npm test 5 | -------------------------------------------------------------------------------- /.lintstagedrc.json: -------------------------------------------------------------------------------- 1 | { 2 | "*.{js,jsx,ts,tsx}": "eslint --fix --cache", 3 | "*.css": "stylelint --fix", 4 | "*.{js,jsx,ts,tsx,css,html,json,md,mdx}": "prettier --write" 5 | } 6 | -------------------------------------------------------------------------------- /.nvmrc: -------------------------------------------------------------------------------- 1 | v14.15.5 2 | -------------------------------------------------------------------------------- /.prettierignore: -------------------------------------------------------------------------------- 1 | node_modules 2 | .DS_Store 3 | dist 4 | dist-ssr 5 | *.local 6 | .eslintcache -------------------------------------------------------------------------------- /.prettierrc.json: -------------------------------------------------------------------------------- 1 | { 2 | "singleQuote": true 3 | } 4 | -------------------------------------------------------------------------------- /.stylelintignore: -------------------------------------------------------------------------------- 1 | node_modules 2 | .DS_Store 3 | dist 4 | dist-ssr 5 | *.local 6 | .eslintcache -------------------------------------------------------------------------------- /.stylelintrc.json: -------------------------------------------------------------------------------- 1 | { 2 | "extends": ["stylelint-config-standard", "stylelint-config-prettier"] 3 | } 4 | -------------------------------------------------------------------------------- /Dockerfile: -------------------------------------------------------------------------------- 1 | FROM node:14-slim 2 | 3 | WORKDIR /app 4 | 5 | # Setup a path for using local npm packages 6 | RUN mkdir -p /opt/node_modules 7 | 8 | COPY ./package.json /app 9 | COPY ./package-lock.json /app 10 | 11 | RUN npm ci 12 | 13 | COPY ./ /app 14 | 15 | RUN npm run client:build 16 | # server build needs to run after client build because the client build using Vite 17 | # removes the dist/ folder before compiling its code 18 | RUN npm run server:build 19 | 20 | EXPOSE 3001 21 | 22 | CMD ["npm", "start"] 23 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | MIT License 2 | 3 | Copyright (c) 2021 Leon Machens 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in all 13 | copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | SOFTWARE. 22 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # Vite React Express Docker Boilerplate 2 | 3 | > Quickly bootstrap a new project with Vite React Express Boilerplate. 4 | 5 | This boilerplate is a fork of [lmachens/vite-boilerplate](https://github.com/lmachens/vite-boilerplate), but replaces TypeScript with JavaScript, adds Docker, and removes Storybook. 6 | 7 | This boilerplate contains all the tools you need to build a modern web app with Vite, Docker, React, and Express. You can use it to quickly bootstrap your project. 8 | 9 | ESLint, stylelint, prettier, husky and lintstaged are configured to give you a solid development experience. 10 | 11 | ## Installing / Developing 12 | 13 | First, [create a repository from this template](https://docs.github.com/en/github/creating-cloning-and-archiving-repositories/creating-a-repository-on-github/creating-a-repository-from-a-template). 14 | 15 | Now you are ready to go: 16 | 17 | ```shell 18 | docker-compose build 19 | ``` 20 | 21 | This will install the dependencies required to run the boilerplate. 22 | 23 | ```shell 24 | docker-compose up 25 | ``` 26 | 27 | Boom! The Docker container will run your server and client in development mode. 28 | 29 | The default PORTS are: 30 | 31 | - `3001` for the server 32 | - `3000` for the client 33 | 34 | You can configure the server port by setting the `PORT` environment variable in `.env`. 35 | 36 | | KEY | VALUE | 37 | | ---- | ------------------------------------------------------------- | 38 | | PORT | (Optional) Port for the server environment (defaults to 3001) | 39 | 40 | ## Building 41 | 42 | To build the Docker image, run: 43 | 44 | ```shell 45 | docker build -t vite-react-express . 46 | ``` 47 | 48 | To run the image locally: 49 | 50 | ```shell 51 | docker run --rm --name vite-react-express -p 3001:3001 vite-react-express:latest 52 | ``` 53 | 54 | and navigate to `http://localhost:3001`. 55 | 56 | In production, you have a single server serving everything. 57 | 58 | `/api/*` is the API endpoint. 59 | `/*` is the client. 60 | 61 | ## Tests 62 | 63 | A test runner is not installed (right now). But ESLint and Prettier are checked on commit and pushed thanks to husky and lintstaged. 64 | 65 | ## Licensing 66 | 67 | MIT 68 | -------------------------------------------------------------------------------- /docker-compose.yml: -------------------------------------------------------------------------------- 1 | version: '3.5' 2 | services: 3 | app: 4 | build: . 5 | container_name: vite-react-express 6 | command: npm run dev 7 | image: vite-react-express:latest 8 | ports: 9 | - '3000:3000' 10 | - '3001:3001' 11 | volumes: 12 | - .:/app 13 | -------------------------------------------------------------------------------- /index.html: -------------------------------------------------------------------------------- 1 | 2 | 3 |
4 | 5 | 6 | 7 |17 | 20 |
21 |
22 | Edit App.jsx
and save to test HMR updates.
23 |
SVG path: {`${import.meta.env.VITE_SVG_PATH}`}
26 |27 | 33 | Learn React 34 | 35 | {' | '} 36 | 42 | Vite Docs 43 | 44 |
45 |{message}
; 14 | } 15 | 16 | export default Welcome; 17 | -------------------------------------------------------------------------------- /src/client/components/Welcome/Welcome.module.css: -------------------------------------------------------------------------------- 1 | .message { 2 | font-weight: bold; 3 | } 4 | -------------------------------------------------------------------------------- /src/client/favicon.svg: -------------------------------------------------------------------------------- 1 | 16 | -------------------------------------------------------------------------------- /src/client/globals.css: -------------------------------------------------------------------------------- 1 | body { 2 | margin: 0; 3 | font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', 'Roboto', 'Oxygen', 4 | 'Ubuntu', 'Cantarell', 'Fira Sans', 'Droid Sans', 'Helvetica Neue', 5 | sans-serif; 6 | -webkit-font-smoothing: antialiased; 7 | -moz-osx-font-smoothing: grayscale; 8 | } 9 | 10 | code { 11 | font-family: source-code-pro, Menlo, Monaco, Consolas, 'Courier New', 12 | monospace; 13 | } 14 | -------------------------------------------------------------------------------- /src/client/logo.svg: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /src/client/main.jsx: -------------------------------------------------------------------------------- 1 | import React from 'react'; 2 | import ReactDOM from 'react-dom'; 3 | import './globals.css'; 4 | import App from './App'; 5 | 6 | ReactDOM.render( 7 |