🔧 一、环境准备(全平台通用)
- 基础依赖
- Rust编译环境:安装最新稳定版Rust(≥1.65)
curl --proto '=https' --tlsv1.2 -sSf https://sh.rustup.rs | shsource "$HOME/.cargo/env"
- Node.js运行时:需LTS版本(≥18.x)
# Ubuntu示例curl -fsSL https://deb.nodesource.com/setup_18.x | sudo -E bash -sudo apt-get install -y nodejs
- Rust编译环境:安装最新稳定版Rust(≥1.65)
- 项目依赖库
- Linux/macOS:
build-essential(GCC套件)、pkg-config、libssl-devsudo apt install build-essential pkg-config libssl-dev # Ubuntu/Debian
- Windows:安装 Visual Studio Build Tools 并勾选”C++桌面开发”
- Linux/macOS:
🚀 二、安装与本地启动
- 克隆代码库
git clone https://github.com/GraphiteEditor/Graphite.gitcd Graphite
- 安装依赖与编译
- 后端Rust编译(耗时约5-15分钟):
cargo build --release # 生产环境用--release优化性能
- 前端依赖安装:
npm install
- 后端Rust编译(耗时约5-15分钟):
- 启动网页端服务
npm start # 默认监听 http://localhost:8080
- 修改端口:
PORT=3000 npm start - 生产模式:
NODE_ENV=production npm start
🌐 三、生产环境部署(Nginx反向代理)
- 配置Nginx
server {listen 80;server_name graphite.example.com;location / {proxy_pass http://localhost:8080; # 指向本地服务端口proxy_http_version 1.1;proxy_set_header Upgrade $http_upgrade;proxy_set_header Connection 'upgrade';proxy_set_header Host $host;proxy_cache_bypass $http_upgrade;}# 启用HTTPS(需提前部署证书)listen 443 ssl;ssl_certificate /path/to/cert.pem;ssl_certificate_key /path/to/privkey.pem;}
sudo systemctl restart nginx - 防火墙配置
sudo ufw allow 80/tcp # HTTPsudo ufw allow 443/tcp # HTTPSsudo ufw allow 8080/tcp # Graphite服务端口
⚠️ 四、常见问题解决
| 问题现象 | 解决方案 |
|---|---|
| Rust编译失败 | 更新工具链:rustup update 并检查libssl-dev是否安装 |
| npm install卡住 | 切换国内源:npm config set registry https://registry.npmmirror.com |
| 页面加载空白 | 清理缓存:npm run clean && npm start |
| 端口冲突 | 修改端口:编辑package.json中start脚本的端口参数 |
| 生产环境静态资源404 | 检查Nginx配置中proxy_pass路径,确保包含/结尾 |
💎 五、高级功能扩展
- Docker容器化部署
FROM node:18-alpine AS frontendWORKDIR /appCOPY . .RUN npm install && npm run buildFROM rust:1.65 AS backendWORKDIR /usr/src/graphiteCOPY . .RUN cargo build --release# 运行阶段镜像(示例)CMD ["npm", "start"]
- 云服务集成
- AWS/Azure:使用EC2/VM部署,绑定弹性IP
- Kubernetes:通过Helm Chart自动化部署
主编写在最后:Graphite Editor通过Rust+Web技术栈实现了高性能图形编辑能力,其网页端服务部署需重点关注编译环境一致性与生产环境网络隔离。建议首次部署后运行官方示例测试渲染功能:
cargo test --package graphite-core --test rendering