Setting Up Local Development Environment
This guide will help you set up and run the documentation site locally for testing and development.
Prerequisites
Before you begin, ensure you have the following installed:
Initial Setup
1. Clone the Repository
# Using HTTPS
git clone https://github.com/your-org/your-docs-repo.git
# Using SSH
git clone git@github.com:your-org/your-docs-repo.git
2. Install Dependencies
# Navigate to the project directory
cd your-docs-repo
# Install dependencies
npm install
Alternatively, using Yarn:
yarn
Running the Development Server
Starting the Server
# Start the development server
npm start
Alternatively, using Yarn:
yarn start
This will:
- Start the local development server
- Open your default browser to
http://localhost:3000
- Enable hot-reloading for instant preview of changes
Development Server Features
- Hot Reloading: Changes to content are reflected immediately
- Error Reporting: Build errors are shown in the browser
- Search: Local search functionality works as in production
- Asset Handling: Images and other assets are served locally
Testing Your Changes
1. Content Changes
- Edit any Markdown file in the
docs
directory - Save the file
- The browser will automatically refresh
- Review your changes
2. Building the Site
# Build the site for production
npm run build
# Serve the built site locally
npm run serve
Alternatively, using Yarn:
yarn build
yarn serve
This helps ensure your changes will work in production.
Common Issues and Solutions
1. Installation Problems
# Clear npm cache
npm cache clean --force
# Remove node_modules and reinstall
rm -rf node_modules
npm install
2. Port Conflicts
If port 3000 is in use:
- Kill the process using the port:
# Windows
netstat -ano | findstr :3000
taskkill /PID <PID> /F
# Mac/Linux
lsof -i :3000
kill -9 <PID> - Or change the port:
# Windows
set PORT=3001 && npm start
# Mac/Linux
PORT=3001 npm start
3. Build Errors
- Check console output for error messages
- Verify all dependencies are installed
- Clear the cache:
npm run clear
Development Best Practices
1. Branch Management
# Create a new branch for your changes
git checkout -b feature/my-changes
# Make your changes and commit them
git add .
git commit -m "Description of changes"
# Push to remote repository
git push origin feature/my-changes
2. Configuration Changes
When modifying docusaurus.config.js
:
- Stop the development server
- Make your changes
- Restart the server
3. Performance Testing
- Build the site:
npm run build
- Check the build output for:
- Bundle sizes
- Page load times
- Resource optimization
Deployment Preview
Before pushing to production:
-
Build the Site
npm run build
-
Test the Production Build
npm run serve
-
Check for Issues
- Test navigation
- Verify images load
- Check internal links
- Test search functionality
Additional Tools
1. Debugging
# Enable debug mode
DEBUG=* npm start
2. Performance Monitoring
# Run lighthouse in CLI
npm install -g lighthouse
lighthouse http://localhost:3000
3. Link Checking
# Install link checker
npm install -g broken-link-checker
# Check all links
blc http://localhost:3000 -ro
Remember: Always test your changes locally before pushing them to ensure a smooth deployment process.