Mermaid Deployment and Usage Guide
Prerequisites
- Node.js (version 16 or higher)
- npm (version 8 or higher)
- TypeScript (for development)
- Git (for cloning the repository)
- D3.js (required dependency for rendering)
- ELK.js (for layout algorithms)
Installation
1. Clone the Repository
git clone https://github.com/mermaid-js/mermaid.git
cd mermaid
2. Install Dependencies
npm install
3. Build the Project
npm run build
4. Run Tests
npm test
Configuration
Environment Variables
Mermaid supports various configuration options through the MermaidConfig interface. Key configuration options include:
- theme:
'default' | 'base' | 'dark' | 'forest' | 'neutral' | 'null' - themeCSS: Custom CSS for theming
- themeVariables: Custom theme variables
- securityLevel: Security configuration for diagram rendering
Configuration File
You can create a configuration file or pass options directly to the Mermaid initialization:
mermaid.initialize({
theme: 'dark',
securityLevel: 'strict',
startOnLoad: true
});
Build & Run
Development Mode
npm run dev
Production Build
npm run build
Running Tests
npm test
Linting
npm run lint
Deployment
CDN Deployment
Mermaid is available on jsDelivr CDN:
<script src="https://cdn.jsdelivr.net/npm/mermaid/dist/mermaid.min.js"></script>
npm Package Deployment
npm publish
Docker Deployment
docker build -t mermaid .
docker run -p 8080:8080 mermaid
Static Site Deployment
For static sites, include the mermaid script and initialize it:
<script src="https://cdn.jsdelivr.net/npm/mermaid/dist/mermaid.min.js"></script>
<script>
mermaid.initialize({ startOnLoad: true });
</script>
Troubleshooting
Common Issues
1. Diagram Not Rendering
Issue: Diagrams fail to render in the browser. Solution: Ensure the mermaid script is loaded before the diagrams are parsed.
mermaid.initialize({
startOnLoad: true
});
2. Security Errors
Issue: Content Security Policy (CSP) blocks diagram rendering. Solution: Add the following to your CSP header:
script-src 'self' 'unsafe-inline' https://cdn.jsdelivr.net;
3. Font Issues
Issue: Text in diagrams appears incorrectly. Solution: Configure font settings in the Mermaid config:
mermaid.initialize({
fontFamily: 'Arial',
fontSize: '14px'
});
4. Layout Problems
Issue: Diagrams are not properly aligned or spaced. Solution: Adjust layout configuration:
mermaid.initialize({
flowchart: {
htmlLabels: true,
curve: 'basis'
}
});
5. Performance Issues
Issue: Large diagrams cause performance problems. Solution: Enable diagram optimization:
mermaid.initialize({
flowchart: {
useMaxWidth: true,
htmlLabels: true
}
});
Getting Help
- Documentation: https://mermaid.js.org/
- Live Editor: https://mermaid.live/
- Discord Community: https://discord.gg/sKeNQX4Wtj
- GitHub Issues: https://github.com/mermaid-js/mermaid/issues
Performance Optimization
For production deployments, consider:
- Minification: Use the minified version of mermaid
- Lazy Loading: Load mermaid only when needed
- Caching: Implement proper caching strategies
- Bundle Optimization: Tree-shake unused diagram types
<script src="https://cdn.jsdelivr.net/npm/mermaid/dist/mermaid.min.js"></script>