Since version 8, electron-builder rebuilds only production dependencies, so you are not forced to use the two package.json structure.
Overview
The two package.json structure separates development dependencies from application dependencies by using two separatepackage.json files:
- Development (
./package.json) - Root package.json for development environment and build scripts - Application (
./app/package.json) - Application package.json distributed with the final packaged app
Structure
Root package.json (Development)
Thepackage.json at the root of your project declares dependencies for your development environment and build scripts in devDependencies.
App package.json (Production)
Thepackage.json in the app directory declares your application dependencies. Only this directory is distributed with the final, packaged application.
app/package.json
All metadata fields (
version, name, etc.) should be in the app/package.json.Why Use Two package.json?
Native Module Compilation
Native npm modules (written in C, not JavaScript) need different compilation targets:- Application dependencies - Compiled against Electron runtime
- Development dependencies - Compiled against local Node.js environment
Simplified File Management
No need to specify which files to include in the app using the files configuration, because development files reside outside theapp directory.
Automatic Dependency Installation
To ensure dependencies are always updated based on both files, add apostinstall script to your development package.json:
npm install within your app directory whenever you install or update dependencies in the root directory.