Simple boilerplate setup for fullstack react/express/node applications
- Clone or download this repository
git clone https://github.com/ziggysauce/ziggy-react-app.git - In your terminal, navigate to the root directory
cd ziggy-react-app - Install dependencies
npm install
- Run script for development build:
npm run build:dev - In browser, application is served at
http://localhost:8080
- Add a
.envfile to the root of your directory- Add the following code to your
.envfile:PORT=5000 SESSION_SECRET=<your_session_secret_here> - Add your own
SESSION_SECRETvalue
- Add the following code to your
- Run script to start up app:
npm start prestartscript will run and createdistdirectory with production build
- React v16
- Webpack v4
- Chunk hash/caching
- Source maps
- Clean re-build of HTML file
- Development Build
- Hot module reload (React Hot Loader)
- Production Build
- Separate injected stylesheet (Extract Text Plugin)
- JS Compression/Minification (Uglify JS Plugin)
- Babel
- SASS
- Express
- Middleware
- Jest
- ESLint (AirBnB Rules)
ziggy-react-app/ # application root directory
├── client/ # frontend directory
│ ├── dist/ # production code directory ignored by .gitignore file
│ ├── src/ # development code directory
│ │ ├── __tests__ # jest testing directory
│ │ │ ├── __snapshots__/ # jest snapshots directory (created after running tests)
│ │ │ └── app.test.js # initial test file
│ │ ├── components/ # react components directory
│ │ │ ├── App.js # initial App.js file
│ │ │ └── Credit.js # author information; delete file after opening
│ │ ├── styles/ # sass styles directory
│ │ │ ├── components/ # sass components directory
│ │ │ │ └── _app.scss # initial styling for app component
│ │ │ ├── setup/ # sass setup directory
│ │ │ │ ├── _base.scss # base styling
│ │ │ │ └── _variables.scss # sass variables
│ │ │ └── main.scss # root sass file (import other files here)
│ │ ├── index.html # template HTML file
│ │ └── index.js # application entry point
├── server/ # backend directory
│ ├── middleware/ # server middleware directory
│ │ ├── cors.js # CORS middleware
│ │ ├── index.js # middleware configuration file
│ │ └── session.js # express-session middleware
│ └── server.js # express server entry point
├── .babelrc # babel configuration file
├── .eslintrc.js # eslint configuration file
├── webpack.common.js # base webpack configuration
├── webpack.dev.js # development build webpack configuration
└── webpack.prod.js # production build webpack configuration
| npm <script> | Function/Description |
|---|---|
| prestart | Run webpack production build script before express server |
| start | Starts app on express server at localhost:5000 with node |
| serve | Starts app on express server at localhost:5000 with nodemon |
| test | Runs all tests files (.test.js type) |
| test:verbose | Displays individuals test results |
| test:coverage | Collects test coverage information and reports output |
| build:dev | Runs webpack developement build (HMR enabled) at localhost:8080 |
| build:prod | Runs webpack production build (dist directory created) |
- Frontend
- Delete the
Credit.jsfile - Edit the
App.jsfile - Edit the
_app.scssfile - SASS styling:
- Be sure to add an underscore
_before new.scssfiles - Add new scss files to
main.scssas an import (order matters)
- Be sure to add an underscore
- Delete the
- Backend
- Add a
.envfile to the root of your directory- Add the following code to your
.envfile:PORT=5000 SESSION_SECRET=<your_session_secret_here> - Add your own
SESSION_SECRETvalue - Edit .env variables however you see fit
- Removing a variable from here may require changes throughout the app where
process.envis called
- Add the following code to your
- Add a
- Testing
- Run
npm testto start all jest testing - Run
npm run test:verboseto see jest testing details - Run
npm run test:coverageto create coverage directory- Run
open coverage/lcov-report/index.htmlto see jest testing coverage
- Run
- Run
This react app boilerplate is open source. Any feedback, issues, contributions, and requests are appreciated and encouraged.
For more information:
Contributing Instructions
License
If you found this repository helpful, please give me a follow and star this repository. Thanks for all the support!