Command-line interface for Capacitor cross-platform native runtime that enables building web apps for iOS, Android, and other platforms
—
Quality
Pending
Does it follow best practices?
Impact
Pending
No eval scenarios have been run
Capacitor CLI provides comprehensive asset management for copying and synchronizing web assets between web and native projects through command-line interfaces. Asset management functions are handled internally and are not exposed as exportable functions.
Copy web application build files into native platform projects.
Command:
npx cap copy [platform] [options]Options:
--inline - Inline all source maps for easier debugging on mobile devicesExamples:
# Copy to all platforms
npx cap copy
# Copy to specific platform
npx cap copy ios
npx cap copy android
# Copy with inline source maps for debugging
npx cap copy android --inlineWhat it does:
webDir to native platform web directoriesSynchronize web assets and update native dependencies in a single operation (combines copy + update).
Command:
npx cap sync [platform] [options]Options:
--deployment - Use deployment option for pod install (iOS)--inline - Inline all source maps for easier debugging on mobile devicesExamples:
# Sync all platforms
npx cap sync
# Sync specific platform
npx cap sync ios
# Sync with deployment flag (iOS)
npx cap sync ios --deployment
# Sync with inline source maps
npx cap sync android --inlineWhat it does:
Update native plugins and dependencies based on package.json without copying web assets.
Command:
npx cap update [platform] [options]Options:
--deployment - Use deployment option for pod install (iOS)Examples:
# Update all platforms
npx cap update
# Update specific platform
npx cap update ios
# Update with deployment flag
npx cap update ios --deploymentWhat it does:
The CLI processes the configured web directory (webDir in capacitor.config.ts):
// Example capacitor.config.ts
const config: CapacitorConfig = {
appId: 'com.example.app',
appName: 'My App',
webDir: 'dist', // Source directory for web assets
bundledWebRuntime: false
};Default behavior:
Inline source maps (--inline flag):
iOS:
ios/App/App/public/ios/App/App/capacitor.config.jsonAndroid:
android/app/src/main/assets/public/android/app/src/main/assets/capacitor.config.jsonBuild your web app:
npm run buildSync assets and dependencies:
npx cap syncRun on device:
npx cap run ios
npx cap run androidFor live reload during development:
# Run with live reload
npx cap run ios --live-reload --host 192.168.1.100 --port 3000
npx cap run android --live-reload --host 192.168.1.100 --port 3000Build optimized web app:
npm run buildCopy assets (no source maps inline):
npx cap copyBuild native apps:
npx cap build ios
npx cap build androidCheck for common asset and configuration issues:
# Check all platforms
npx cap doctor
# Check specific platform
npx cap doctor ios
npx cap doctor androidThe doctor command validates:
const config: CapacitorConfig = {
webDir: 'dist', // Directory containing built web assets
bundledWebRuntime: false, // Whether to bundle Capacitor runtime
server: { // Development server configuration
url: 'http://localhost:3000',
cleartext: true
}
};Configure which files to exclude from copying:
const config: CapacitorConfig = {
// ... other config
cordova: {
preferences: {
// Cordova preferences that affect asset handling
}
}
};Asset management is implemented through internal modules:
/tasks/copy.ts/tasks/sync.ts/tasks/update.ts/tasks/sourcemaps.tsThese internal functions are called by CLI commands but are not part of the public API.
Install with Tessl CLI
npx tessl i tessl/npm-capacitor--cli