electron-builder uses glob patterns to determine which files to include or exclude from your application package. Understanding these patterns is essential for controlling your application’s size and content.Documentation Index
Fetch the complete documentation index at: https://mintlify.com/electron-userland/electron-builder/llms.txt
Use this file to discover all available pages before exploring further.
Glob Pattern Syntax
Basic Patterns
| Pattern | Description | Example |
|---|---|---|
* | Matches 0 or more characters in a single path portion | *.js matches all JavaScript files |
? | Matches exactly 1 character | file?.txt matches file1.txt, fileA.txt |
[...] | Matches a range of characters (like RegExp) | file[0-9].js matches file0.js through file9.js |
[!...] or [^...] | Matches any character NOT in the range | file[!0-9].js excludes numbered files |
** | Matches zero or more directories (globstar) | src/**/* matches all files in src and subdirectories |
Extended Patterns
| Pattern | Description | Example |
|---|---|---|
!(pattern|pattern) | Matches anything that does NOT match any of the patterns | !(*.spec|*.test).js excludes test files |
?(pattern|pattern) | Matches zero or one occurrence of the patterns | file?(.min).js matches file.js or file.min.js |
+(pattern|pattern) | Matches one or more occurrences of the patterns | file+(1|2|3).js matches file1.js, file11.js, etc. |
*(pattern|pattern) | Matches zero or more occurrences of the patterns | file*(a|b).js matches file.js, filea.js, fileab.js |
@(pattern|pattern) | Matches exactly one of the patterns | @(file1|file2).js matches only file1.js or file2.js |
Using File Patterns
Including Files
Define which files to include in your application:package.json
If a directory is matched, all its contents are copied automatically. You can specify just
foo to copy the entire foo directory.Excluding Files
Use the! prefix to exclude files:
package.json
Excluding Directories
Solution: Use the${/*} macro:
Multiple Glob Patterns
Patterns are processed in order, allowing you to include exceptions to exclusions:File Macros
You can use macros in file patterns, artifact names, and publish URLs. Macros are replaced at build time.Available Macros
| Macro | Expands To | Description |
|---|---|---|
${arch} | ia32, x64, arm64 | CPU architecture (removed if no arch with leading space, -, _) |
${os} | mac, linux, win | Operating system |
${platform} | darwin, linux, win32 | Node.js process.platform value |
${name} | package.json name | Application name from package.json |
${productName} | Sanitized product name | Product name (sanitized for filenames) |
${version} | package.json version | Application version |
${channel} | beta, alpha, etc. | Detected prerelease component from version |
${env.ENV_NAME} | Environment variable value | Any environment variable |
${buildVersion} | Build version | From AppInfo |
${buildNumber} | Build number | From AppInfo |
Using Macros in Patterns
package.json
Environment Variable Macros
electron-builder.yml
The
${ext} macro is also supported in artifact file name templates to represent the file extension.Common Patterns
Development vs Production Files
Exclude Source Files
Platform-Specific Resources
Include Build Resources
extraResources and extraFiles
For files that should not be in the app.asar archive:FileSet with Patterns
See Application Contents for more details on
extraResources and extraFiles.Performance Tips
- Be specific: Use specific patterns instead of broad patterns with many exclusions
- Exclude unnecessary files: Remove development files, documentation, and test files
- Use asarUnpack carefully: Unpacking too many files can slow down your app