React Boilerplate Deployment and Usage Guide
Prerequisites
- Node.js: v8.15.1 or higher
- npm: v5 or higher
- Git: For cloning the repository
- Optional: A code editor with ESLint and Prettier extensions for best development experience
Installation
-
Clone the repository
git clone --depth=1 https://github.com/react-boilerplate/react-boilerplate.git <YOUR_PROJECT_NAME> -
Navigate to the project directory
cd <YOUR_PROJECT_NAME> -
Install dependencies and clean git repository
npm run setup -
Start the development server
npm startThe application will be available at
http://localhost:3000 -
Clean example app (optional)
npm run cleanThis removes the example app and prepares the project for your own code.
Configuration
Environment Variables
The project uses environment variables for configuration. Create a .env file in the root directory:
# Basic configuration
NODE_ENV=development
# Optional: Customize port
PORT=3000
# Optional: API endpoints
API_URL=http://localhost:8080/api
Available Scripts
The project includes several npm scripts for development and build processes:
npm start- Starts the development server with hot reloadingnpm run build- Creates a production build in thebuildfoldernpm run start:prod- Runs the production build locallynpm test- Runs all testsnpm run test:watch- Runs tests in watch modenpm run generate- Runs the generator CLI for creating components, containers, etc.
Build & Run
Development
npm start
Features:
- Hot module replacement
- State preservation on hot reload
- Error overlay
- Source maps
Production Build
npm run build
The build process includes:
- Code splitting with dynamic imports
- Tree shaking
- Minification
- Asset optimization
- Service worker generation for offline support
Running Production Build Locally
npm run start:prod
This serves the production build from the build folder.
Deployment
Static Hosting (Recommended)
React Boilerplate generates a static build that can be deployed to any static hosting service:
-
Build the application
npm run build -
Deploy to your preferred platform:
Vercel (formerly Zeit)
- Connect your GitHub repository
- Select the project
- Configure build command:
npm run build - Output directory:
build
Netlify
- Drag and drop the
buildfolder - Or connect your repository
- Build command:
npm run build - Publish directory:
build
GitHub Pages
npm run deploy
(Requires gh-pages package and proper configuration)
Docker Deployment
Create a Dockerfile:
FROM node:14-alpine as build
WORKDIR /app
COPY package*.json ./
RUN npm ci
COPY . .
RUN npm run build
FROM nginx:alpine
COPY --from=build /app/build /usr/share/nginx/html
EXPOSE 80
CMD ["nginx", "-g", "daemon off;"]
Build and run:
docker build -t my-app .
docker run -p 80:80 my-app
Custom Server Deployment
For server-side rendering or API integration, deploy to platforms like:
- Heroku: Push to Heroku Git remote
- AWS Elastic Beanstalk: Deploy the build folder
- Digital Ocean App Platform: Connect repository and configure build settings
Troubleshooting
Common Issues and Solutions
1. Port already in use
npm start -- --port 3001
Or set PORT=3001 in your .env file.
2. Module not found errors
rm -rf node_modules
npm install
3. Hot reload not working
- Check if
npm startis running - Verify no conflicting processes on port 3000
- Clear browser cache and reload
4. Build fails
- Check for syntax errors in your code
- Run
npm testto identify issues - Ensure all dependencies are installed correctly
5. Service worker not updating
- Check the service worker registration in your browser's dev tools
- Ensure the cache is properly invalidated
- Verify the
offline-pluginconfiguration
Generator Issues
If the generator CLI doesn't work:
npm install -g plop
plop
ESLint/Prettier Issues
Ensure your editor has the appropriate extensions installed:
- ESLint extension for automatic linting
- Prettier extension for code formatting
Performance Issues
If the app is slow:
- Check bundle size with
npm run analyze - Optimize images and assets
- Implement code splitting for large components
Testing Issues
If tests fail:
- Run
npm test -- --verbosefor detailed output - Check test files for syntax errors
- Ensure test environment is properly configured
Additional Resources
- Documentation: The Hitchhiker's Guide to react-boilerplate
- Video Tutorial: Structuring React.js apps with scalability in mind
- Community Support: Spectrum Chat
- Issue Tracker: GitHub Issues