分类 NPM 下的文章

package.json

{
    "name": "",
    "version": "1.0.0",
    "description": "",
    "author": "",
    "main": "main.js",
    "scripts": {
        "start": "electron .",
        "build": "electron-builder",
        "build-win32": "electron-builder --ia32",
        "build-win64": "electron-builder --x64"
    },
    "repository": "",
    "keywords": [],
    "license": "",
    "devDependencies": {
        "electron": "^17.0.1",
        "electron-builder": "^22.14.13"
    },
    "build": {
        "productName": "",
        "appId": "",
        "copyright": "",
        "compression": "maximum",
        "directories": {
            "output": "build"
        },
        "asar": false,
        "win": {
            "icon": "logo/256.ico",
            "artifactName": "${productName}_setup_${version}.${ext}"
        },
        "mac": {
            "icon": "logo/512.png",
            "artifactName": "${productName}_setup_${version}.${ext}"
        },
        "linux": {
            "icon": "logo/256.ico",
            "artifactName": "${productName}_setup_${version}.${ext}"
        },
        "nsis": {
            "oneClick": false,
            "perMachine": true,
            "allowElevation": true,
            "allowToChangeInstallationDirectory": true,
            "installerIcon": "logo/256.ico",
            "uninstallerIcon": "logo/256.ico",
            "installerHeaderIcon": "logo/256.ico",
            "createDesktopShortcut": true,
            "createStartMenuShortcut": true,
            "shortcutName": ""
        }
    }
}

打包程序

npm run build
# 以管理员权限运行,避免权限不足报错

# 32位
electron-packager . 'ProjectName' --platform=win32 --arch=ia32 --icon=logo.ico --out=./OutputPath --asar --app-version=1.0.0

# 64位
electron-packager . 'ProjectName' --platform=win32 --arch=x64 --icon=logo.ico --out=./OutputPath --asar --app-version=1.0.0

npm config set registry https://registry.npm.taobao.org --global
npm config set disturl https://npm.taobao.org/dist --global

yarn config set registry https://registry.npm.taobao.org --global
yarn config set disturl https://npm.taobao.org/dist --global