Deployment FAQ
This page covers frequently asked questions about deploying uni-app applications.
Platform-specific Deployment
How to deploy to WeChat Mini Program?
Build the project
bashnpm run build:mp-weixin
Open WeChat Developer Tools
- Import the
dist/build/mp-weixin
directory - Configure AppID in
manifest.json
- Test and submit for review
- Import the
Common issues
- Ensure all APIs used are supported by WeChat Mini Program
- Check domain whitelist configuration
- Verify component compatibility
How to deploy to Alipay Mini Program?
Build the project
bashnpm run build:mp-alipay
Open Alipay Mini Program Studio
- Import the
dist/build/mp-alipay
directory - Configure AppID and other settings
- Test functionality
- Import the
How to deploy to H5 (Web)?
Build the project
bashnpm run build:h5
Deploy to web server
- Upload
dist/build/h5
directory to your web server - Configure routing (for SPA mode)
- Set up HTTPS if needed
- Upload
Router configuration
javascript// For history mode, configure server redirects // Apache .htaccess example: RewriteEngine On RewriteRule ^(?!.*\.).*$ /index.html [L]
How to deploy to App (iOS/Android)?
Build the project
bashnpm run build:app-plus
Use HBuilderX for packaging
- Open project in HBuilderX
- Configure App icons and splash screens
- Set up certificates and signatures
- Generate installation packages
Cloud Deployment
How to deploy using uniCloud?
Initialize uniCloud
bash# Create cloud functions directory mkdir uniCloud-aliyun # or mkdir uniCloud-tcb
Configure cloud functions
- Create cloud functions in HBuilderX
- Upload and deploy functions
- Configure database and storage
Frontend integration
javascript// Initialize uniCloud const db = uniCloud.database() // Call cloud functions uniCloud.callFunction({ name: 'functionName', data: {} })
How to use CDN for static resources?
Configure publicPath
javascript// vue.config.js module.exports = { publicPath: process.env.NODE_ENV === 'production' ? 'https://cdn.example.com/' : '/' }
Upload static files
- Build the project
- Upload static files to CDN
- Update resource references
Environment Configuration
How to configure different environments?
Create environment files
.env.development .env.production .env.staging
Environment variables
bash# .env.production VUE_APP_API_URL=https://api.production.com VUE_APP_ENV=production
Use in code
javascriptconst apiUrl = process.env.VUE_APP_API_URL
How to handle cross-platform differences?
Conditional compilation
javascript// #ifdef H5 // H5-specific code // #endif // #ifdef MP-WEIXIN // WeChat Mini Program specific code // #endif
Platform detection
javascript// Check current platform if (uni.getSystemInfoSync().platform === 'ios') { // iOS specific logic }
Performance Optimization
How to optimize bundle size?
Enable tree shaking
javascript// vue.config.js module.exports = { configureWebpack: { optimization: { usedExports: true } } }
Code splitting
javascript// Use dynamic imports const LazyComponent = () => import('./LazyComponent.vue')
Remove unused dependencies
bashnpm prune # or use webpack-bundle-analyzer npm install --save-dev webpack-bundle-analyzer
How to implement lazy loading?
Page-level lazy loading
javascript// pages.json { "pages": [ { "path": "pages/index/index", "style": { "enablePullDownRefresh": false } } ], "subPackages": [ { "root": "pages/sub", "pages": [ { "path": "detail/detail" } ] } ] }
Component lazy loading
javascriptexport default { components: { LazyComponent: () => import('./LazyComponent.vue') } }
Security Considerations
How to secure API endpoints?
Use HTTPS
- Always use HTTPS in production
- Configure SSL certificates properly
API authentication
javascript// Add authentication headers uni.request({ url: 'https://api.example.com/data', header: { 'Authorization': 'Bearer ' + token } })
Input validation
- Validate all user inputs
- Sanitize data before processing
How to handle sensitive data?
Environment variables
- Store sensitive data in environment variables
- Never commit secrets to version control
Secure storage
javascript// Use secure storage for sensitive data uni.setStorageSync('token', encryptedToken)
Troubleshooting
Common deployment errors
Build failures
- Check Node.js version compatibility
- Clear node_modules and reinstall
- Verify all dependencies are installed
Runtime errors
- Check console for error messages
- Verify API endpoints are accessible
- Test on different devices/platforms
Performance issues
- Optimize images and assets
- Implement proper caching strategies
- Monitor network requests
How to debug production issues?
Enable source maps
javascript// vue.config.js module.exports = { productionSourceMap: true }
Error tracking
javascript// Global error handler Vue.config.errorHandler = (err, vm, info) => { console.error('Global error:', err, info) // Send to error tracking service }
Logging
javascript// Conditional logging if (process.env.NODE_ENV === 'development') { console.log('Debug info:', data) }
Best Practices
Deployment checklist
- [ ] Test on all target platforms
- [ ] Optimize images and assets
- [ ] Configure proper caching headers
- [ ] Set up error monitoring
- [ ] Verify SSL certificates
- [ ] Test offline functionality
- [ ] Check performance metrics
- [ ] Validate accessibility
- [ ] Review security settings
- [ ] Backup deployment artifacts
Continuous Integration
Set up CI/CD pipeline
yaml# GitHub Actions example name: Deploy on: push: branches: [main] jobs: deploy: runs-on: ubuntu-latest steps: - uses: actions/checkout@v2 - name: Setup Node.js uses: actions/setup-node@v2 with: node-version: '16' - name: Install dependencies run: npm ci - name: Build run: npm run build - name: Deploy run: npm run deploy
Automated testing
- Unit tests
- Integration tests
- End-to-end tests
For more deployment-related questions, please check our community forum or contact us.