Skip to main content
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.

Glob Pattern Syntax

Basic Patterns

PatternDescriptionExample
*Matches 0 or more characters in a single path portion*.js matches all JavaScript files
?Matches exactly 1 characterfile?.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 rangefile[!0-9].js excludes numbered files
**Matches zero or more directories (globstar)src/**/* matches all files in src and subdirectories

Extended Patterns

PatternDescriptionExample
!(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 patternsfile?(.min).js matches file.js or file.min.js
+(pattern|pattern)Matches one or more occurrences of the patternsfile+(1|2|3).js matches file1.js, file11.js, etc.
*(pattern|pattern)Matches zero or more occurrences of the patternsfile*(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
{
  "build": {
    "files": [
      "dist/**/*",
      "node_modules/**/*",
      "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
{
  "build": {
    "files": [
      "**/*",
      "!**/node_modules/*/{CHANGELOG.md,README.md}",
      "!**/*.{iml,o,hprof,orig,pyc,pyo,rbc,swp,csproj,sln,xproj}",
      "!**/{.DS_Store,.git,.hg,.svn,CVS,RCS,SCCS,__pycache__,thumbs.db,.gitignore,.gitattributes}",
      "!**/node_modules/**/{test,__tests__,tests,powered-test,example,examples}/**",
      "!**/*.{spec.js,test.js}"
    ]
  }
}

Excluding Directories

Be careful when excluding directories. The pattern !doNotCopyMe/**/* would match the files IN the doNotCopyMe directory, but not the directory itself, creating an empty directory.
Solution: Use the ${/*} macro:
{
  "build": {
    "files": [
      "**/*",
      "!doNotCopyMe${/*}"
    ]
  }
}
This correctly excludes both the directory and its contents.

Multiple Glob Patterns

Patterns are processed in order, allowing you to include exceptions to exclusions:
[
  // Match all files
  "**/*",

  // Except for js files in the foo/ directory
  "!foo/*.js",

  // Unless it's foo/bar.js (re-include this specific file)
  "foo/bar.js",
]
{
  "build": {
    "files": [
      "**/*",
      "!**/*.map",
      "dist/important.map"
    ]
  }
}

File Macros

You can use macros in file patterns, artifact names, and publish URLs. Macros are replaced at build time.

Available Macros

MacroExpands ToDescription
${arch}ia32, x64, arm64CPU architecture (removed if no arch with leading space, -, _)
${os}mac, linux, winOperating system
${platform}darwin, linux, win32Node.js process.platform value
${name}package.json nameApplication name from package.json
${productName}Sanitized product nameProduct name (sanitized for filenames)
${version}package.json versionApplication version
${channel}beta, alpha, etc.Detected prerelease component from version
${env.ENV_NAME}Environment variable valueAny environment variable
${buildVersion}Build versionFrom AppInfo
${buildNumber}Build numberFrom AppInfo

Using Macros in Patterns

package.json
{
  "build": {
    "files": [
      "dist/${platform}/**/*",
      "assets/${os}/**/*"
    ],
    "directories": {
      "output": "release/${version}"
    },
    "artifactName": "${productName}-${version}-${os}-${arch}.${ext}"
  }
}

Environment Variable Macros

electron-builder.yml
files:
  - "**/*"
  - "config/${env.NODE_ENV}/**/*"

artifactName: "${productName}-${env.BUILD_TAG}.${ext}"
The ${ext} macro is also supported in artifact file name templates to represent the file extension.

Common Patterns

Development vs Production Files

{
  "build": {
    "files": [
      "dist/**/*",
      "!dist/**/*.map",
      "node_modules/**/*",
      "!node_modules/**/{*.md,*.ts}",
      "package.json"
    ]
  }
}

Exclude Source Files

{
  "build": {
    "files": [
      "**/*",
      "!src${/*}",
      "!**/*.ts",
      "!tsconfig.json",
      "dist/**/*"
    ]
  }
}

Platform-Specific Resources

mac:
  files:
    - "resources/mac/**/*"

win:
  files:
    - "resources/win/**/*"

linux:
  files:
    - "resources/linux/**/*"

Include Build Resources

{
  "build": {
    "files": [
      "**/*",
      "build/icon.*"
    ],
    "directories": {
      "buildResources": "build"
    }
  }
}
Build resources (from the buildResources directory) are NOT packed into the app by default. If you need files like tray icons, explicitly include them in the files pattern.

extraResources and extraFiles

For files that should not be in the app.asar archive:
{
  "build": {
    "extraResources": [
      {
        "from": "assets/",
        "to": ".",
        "filter": ["**/*"]
      }
    ],
    "extraFiles": [
      "LICENSE.txt",
      "README.md"
    ]
  }
}

FileSet with Patterns

extraResources:
  - from: "build/"
    to: "resources/"
    filter:
      - "**/*"
      - "!**/*.map"
See Application Contents for more details on extraResources and extraFiles.

Performance Tips

  1. Be specific: Use specific patterns instead of broad patterns with many exclusions
  2. Exclude unnecessary files: Remove development files, documentation, and test files
  3. Use asarUnpack carefully: Unpacking too many files can slow down your app
{
  "build": {
    "files": [
      "dist/**/*",
      "node_modules/**/*"
    ],
    "asarUnpack": [
      "**/node_modules/sharp/**/*",
      "**/node_modules/sqlite3/**/*"
    ]
  }
}

Build docs developers (and LLMs) love