build command compiles and packages your Native Desktop application into distributable formats for your target platform. This command creates production-ready binaries that can be distributed to end users.
Prerequisites
Before building your project, ensure:- Your project has been created using
native-desktop create - All dependencies are installed (
npm install) - Your application has been tested in development mode
- You have a valid
native-desktop.config.json5configuration file
Basic Usage
To build your project, open the terminal in the root directory of your Native Desktop project and run:With Custom Configuration
If you need to specify a custom configuration file:Command Options
--config (Required)
Path to the project configuration file.
- Type: String
- Default:
native-desktop.config.json5 - Example:
--config my-config.json5
--target (Required)
Output format for the build. The available targets depend on your operating system.
- Type: String
- Required: Yes
--sign (Optional)
Automatically sign the application after building.
- Type: Boolean
- Default:
false
When using
--sign, the CLI will automatically sign your application after the build completes. This requires proper signing credentials to be configured.Supported Target Types
The available build targets vary by platform:- macOS
- Windows
- Linux
Native Desktop supports the following targets on macOS:
Creates a macOS Disk Image (.dmg) file for distribution.
Creates a macOS application bundle (.app) directory.
Creates a macOS Installer Package (.pkg) file.
dmg
Creates a macOS Disk Image (.dmg) file for distribution.- File Extension:
.dmg - Distribution: App Store and direct distribution
- User Experience: Drag-and-drop installation
- Recommended: ✅ Best for public distribution
app
Creates a macOS application bundle (.app) directory.- File Type: Directory bundle
- Distribution: Development and testing
- User Experience: Raw application bundle
- Recommended: For development only
pkg
Creates a macOS Installer Package (.pkg) file.- File Extension:
.pkg - Distribution: Enterprise and Mac App Store
- User Experience: Guided installation wizard
- Recommended: For enterprise distribution
Build Output
After successful execution, the Native Desktop CLI generates build output inside a directory namedbin/ in your project root:
Complete Examples
Building for macOS
Building for Windows
Building for Linux
Build Process
The build command performs the following steps:- Configuration Loading: Reads the configuration file
- Dependency Resolution: Ensures all dependencies are available
- TypeScript Compilation: Compiles TypeScript to JavaScript
- Asset Bundling: Bundles application assets and resources
- Native Packaging: Creates platform-specific package
- Output Generation: Writes build artifacts to
bin/directory - Signing (if
--signflag is used): Signs the application - Verification: Validates the build output
Build Configuration
The build process uses settings from yournative-desktop.config.json5 file. Key configuration options include:
- Application metadata (name, version, description)
- Build targets and architectures
- Icon and asset paths
- Platform-specific settings
- Code signing configuration
Common Issues
Invalid Target Error
Invalid Target Error
Error:
Invalid target "xyz" for platform "mac". Supported targets: dmg, app, pkgSolution: Use a target type that is supported on your current platform. Check the supported targets list for your OS.Configuration File Not Found
Configuration File Not Found
Error:
Configuration file not foundSolution: Ensure the configuration file exists and the path is correct.Build Directory Permission Error
Build Directory Permission Error
Error:
Permission denied: cannot write to bin/Solution: Ensure you have write permissions in the project directory.Missing Dependencies
Missing Dependencies
Error:
Cannot find module 'xyz'Solution: Install all project dependencies before building.Signing Failed
Signing Failed
Error:
Code signing failedSolution: Ensure signing credentials are properly configured. Run the sign command separately for more control.Platform Limitations
Cross-Platform Builds: You can only build for the operating system you are currently using. For example:
- On macOS → Build macOS apps only
- On Windows → Build Windows apps only
- On Linux → Build Linux apps only
- Use a machine running each target OS, or
- Use cloud build services with multiple OS environments, or
- Use virtual machines or containers for each platform
Build Optimization
Production Builds
For production releases, consider:Development Builds
For testing and development:CI/CD Integration
The build command can be integrated into CI/CD pipelines:Best Practices
Test Before Building
Always test your application with
native-desktop run before building for distributionVersion Management
Update version numbers in your config file before each production build
Build Verification
Test built applications on clean systems to ensure all dependencies are included
Code Signing
Always sign production builds to ensure user trust and meet platform requirements