electron-builder.cjs 3.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113
  1. /**
  2. * @type {import('app-builder-lib').Configuration}
  3. * @see https://www.electron.build/configuration/configuration
  4. */
  5. require('dotenv').config()
  6. const pkg = require('./package.json')
  7. const buildNumber = process.env.VITE_APP_BUILD_NUMBER || '0'
  8. const os = require('os')
  9. const path = require('path')
  10. // Fix: electron-builder downloads dmg-builder via @electron/get which incorrectly
  11. // uses ELECTRON_MIRROR for all downloads, causing 404 on npmmirror.
  12. // Use local cached dmgbuild binary directly to bypass the download entirely.
  13. if (!process.env.CUSTOM_DMGBUILD_PATH) {
  14. const dmgbuildPath = path.join(
  15. os.homedir(),
  16. 'Library/Caches/electron-builder/dmg-builder@1.2.0/dmgbuild'
  17. )
  18. process.env.CUSTOM_DMGBUILD_PATH = dmgbuildPath
  19. }
  20. module.exports = {
  21. // --- 基础配置 ---
  22. appId: 'com.zycoo.scas-tool-v2',
  23. productName: 'Scas Tool',
  24. buildVersion: buildNumber, // 映射到 CFBundleVersion (Mac) 和 FileVersion (Win)
  25. buildNumber: buildNumber,
  26. directories: {
  27. buildResources: 'build',
  28. output: 'dist'
  29. },
  30. // --- 钩子脚本 ---
  31. afterAllArtifactBuild: 'build/notarize-dmg.cjs',
  32. // --- 文件包含与忽略 ---
  33. files: [
  34. '!**/.idea/*',
  35. '!**/.vscode/*',
  36. '!src/*',
  37. '!electron.vite.config.{js,ts,mjs,cjs}',
  38. '!vite.config.web.{js,ts,mjs,cjs}',
  39. '!{.eslintcache,eslint.config.mjs,.prettierignore,.prettierrc.yaml,dev-app-update.yml,CHANGELOG.md,README.md}',
  40. '!{.env,.env.*,.npmrc,pnpm-lock.yaml}',
  41. '!{tsconfig.json,tsconfig.node.json,tsconfig.web.json}'
  42. ],
  43. asarUnpack: ['resources/**'],
  44. // --- Windows 配置 ---
  45. win: {
  46. executableName: 'Scas Tool',
  47. // 注意:JS中引用内部变量需加反斜杠转义 \${...},引用JS变量则直接用 ${buildNumber}
  48. artifactName: `\${name}-${pkg.version}.${buildNumber}-setup-\${arch}.\${ext}`,
  49. target: [{ target: 'nsis', arch: ['ia32', 'x64'] }]
  50. },
  51. nsis: {
  52. artifactName: `\${name}-${pkg.version}.${buildNumber}-setup-\${arch}.\${ext}`,
  53. shortcutName: 'Scas Tool',
  54. oneClick: false, // 取消一键安装,允许用户选择
  55. allowToChangeInstallationDirectory: true, // 允许用户修改安装路径
  56. perMachine: true, // true 为安装到 Program Files,false 为 AppData
  57. createDesktopShortcut: true,
  58. createStartMenuShortcut: true,
  59. uninstallDisplayName: 'Scas Tool'
  60. },
  61. // --- macOS 配置 ---
  62. mac: {
  63. notarize: false, // 使用自定义 build/notarize-dmg.cjs 进行公证
  64. hardenedRuntime: true,
  65. entitlements: 'build/entitlements.mac.plist',
  66. entitlementsInherit: 'build/entitlements.mac.plist',
  67. extendInfo: {
  68. NSMicrophoneUsageDescription: "Application requests access to the device's microphone.",
  69. NSDocumentsFolderUsageDescription:
  70. "Application requests access to the user's Documents folder.",
  71. NSDownloadsFolderUsageDescription:
  72. "Application requests access to the user's Downloads folder.",
  73. CFBundleVersion: buildNumber,
  74. CFBundleDevelopmentRegion: 'en',
  75. CFBundleLocalizations: ['en', 'zh_CN']
  76. },
  77. target: [{ target: 'dmg', arch: ['x64', 'arm64'] }]
  78. },
  79. dmg: {
  80. artifactName: `\${name}-${pkg.version}.${buildNumber}-\${arch}.\${ext}`
  81. },
  82. // --- Linux 配置 ---
  83. linux: {
  84. target: ['AppImage', 'snap', 'deb'],
  85. maintainer: 'zycoo.com',
  86. category: 'Utility',
  87. artifactName: `\${name}-${pkg.version}.${buildNumber}.\${ext}`
  88. },
  89. appImage: {
  90. artifactName: `\${name}-${pkg.version}.${buildNumber}.\${ext}`
  91. },
  92. snap: {
  93. artifactName: `\${name}-${pkg.version}.${buildNumber}.\${ext}`
  94. },
  95. deb: {
  96. artifactName: `\${name}-${pkg.version}.${buildNumber}-\${arch}.\${ext}`
  97. },
  98. // --- 其他性能/下载配置 ---
  99. npmRebuild: false,
  100. electronDownload: {
  101. mirror: 'https://npmmirror.com/mirrors/electron/'
  102. }
  103. }