axiuge 发表于 2024-6-2 15:10

利用Nativefier转换成exe的bat-3.0

本帖最后由 axiuge 于 2024-6-3 12:17 编辑

@echo off
chcp 65001 >nul 2>&1

REM 检查是否已安装 Node.js
where node >nul 2>nul
if %errorlevel% neq 0 (
    REM 如果未安装 Node.js,则在线安装
    echo 正在安装 Node.js,请稍候...
    goto install_node
)

REM 检查是否已安装 Nativefier
where nativefier >nul 2>nul
if %errorlevel% neq 0 (
    REM 如果未安装 Nativefier,则在线安装
    echo 正在安装 Nativefier,请稍候...
    npm install nativefier -g
)

REM 提示用户输入程序名称
set /p app_name=请输入程序名称:

REM 提示用户输入要打包的网址
set /p url=请输入要打包的网址:

REM 提示用户提供图标路径(可选)
set /p icon_path=请输入图标文件路径(可选,如果没有则留空):

REM 构建 Nativefier 命令
set nativefier_cmd=nativefier "%url%" --name "%app_name%" --out "%cd%"

if not "%icon_path%"=="" (
    set nativefier_cmd=%nativefier_cmd% --icon "%icon_path%"
)

REM 使用 Nativefier 打包应用程序
%nativefier_cmd% 2>"%cd%\error.txt"

if %errorlevel% equ 0 (
    echo 应用程序已经打包完成!
) else (
    echo 打包过程中出现错误,请查看当前目录下的 error.txt 以获取更多信息。
)

pause
goto end

:install_node
REM 在线安装 Node.js
echo 正在下载并安装 Node.js,请稍候...
bitsadmin /transfer myDownloadJob /download /priority high https://nodejs.org/dist/v16.13.1/node-v16.13.1-x64.msi %temp%\nodejs.msi
msiexec /i %temp%\nodejs.msi /qn /quiet /norestart
if %errorlevel% equ 0 (
    echo Node.js 安装完成!
    goto end
) else (
    echo Node.js 安装失败,请手动安装。
    goto end
)

:end


把代码保存为bat.双击就可以打包exe.

collinchen1218 发表于 2024-6-2 17:10

额,好像体积有点小了……

axiuge 发表于 2024-6-2 17:14

collinchen1218 发表于 2024-6-2 17:10
额,好像体积有点小了……

体积有点小了 没懂啥意思

collinchen1218 发表于 2024-6-2 17:15

axiuge 发表于 2024-6-2 17:14
体积有点小了 没懂啥意思
你看编译出来主程序150多兆,很小吧,再加个运行库

ceciliaaii 发表于 2024-6-2 19:58

又是浏览器套的,太大了

axiuge 发表于 2024-6-2 20:58

collinchen1218 发表于 2024-6-2 17:15
你看编译出来主程序150多兆,很小吧,再加个运行库

这个不是python 是Nativefier。

axiuge 发表于 2024-6-2 21:02

ceciliaaii 发表于 2024-6-2 19:58
又是浏览器套的,太大了

你只能说 类似浏览器,但是不是浏览器。

collinchen1218 发表于 2024-6-2 21:06

ceciliaaii 发表于 2024-6-2 19:58
又是浏览器套的,太大了

用我的方案,用webview2,看签名那里

JakerPower 发表于 2024-6-2 21:49

出错了
rror copying injection files. Error: File inject.js not found. Note that Nativefier expects *local* files, not URLs.
    at maybeCopyScripts (C:\Users\xxx\AppData\Roaming\npm\node_modules\nativefier\src\build\prepareElectronApp.ts:120:13)
    at prepareElectronApp (C:\Users\xxx\AppData\Roaming\npm\node_modules\nativefier\src\build\prepareElectronApp.ts:209:11)
    at buildNativefierApp (C:\Users\xxx\AppData\Roaming\npm\node_modules\nativefier\src\build\buildNativefierApp.ts:197:3)
Failed to convert icon to .ico, skipping. Error: Icon conversion only supported on macOS or Linux. If building for Windows, download/create a .ico and pass it with --icon favicon.ico . If building for macOS/Linux, do it from macOS/Linux
    at iconShellHelper (C:\Users\xxx\AppData\Roaming\npm\node_modules\nativefier\src\helpers\iconShellHelpers.ts:28:11)
    at convertToIco (C:\Users\xxx\AppData\Roaming\npm\node_modules\nativefier\src\helpers\iconShellHelpers.ts:71:10)
    at convertIconIfNecessary (C:\Users\xxx\AppData\Roaming\npm\node_modules\nativefier\src\build\buildIcon.ts:45:36)
    at buildNativefierApp (C:\Users\xxx\AppData\Roaming\npm\node_modules\nativefier\src\build\buildNativefierApp.ts:201:25)
Error during build. Run with --verbose for details. RequestError: getaddrinfo ENOENT github.com
    at ClientRequest.<anonymous> (C:\Users\xxx\AppData\Roaming\npm\node_modules\nativefier\node_modules\got\dist\source\core\index.js:970:111)
    at Object.onceWrapper (node:events:510:26)
    at ClientRequest.emit (node:events:402:35)
    at ClientRequest.emit (node:domain:475:12)
    at ClientRequest.origin.emit (C:\Users\xxx\AppData\Roaming\npm\node_modules\nativefier\node_modules\@szmarczak\http-timer\dist\source\index.js:43:20)
    at TLSSocket.socketErrorListener (node:_http_client:447:9)
    at TLSSocket.emit (node:events:390:28)
    at TLSSocket.emit (node:domain:475:12)
    at emitErrorNT (node:internal/streams/destroy:157:8)
    at emitErrorCloseNT (node:internal/streams/destroy:122:3)
    at processTicksAndRejections (node:internal/process/task_queues:83:21)
    at GetAddrInfoReqWrap.onlookup (node:dns:71:26) {
code: 'ENOENT',
timings: {
    start: 1717335988857,
    socket: 1717335988858,
    lookup: 1717335988864,
    connect: undefined,
    secureConnect: undefined,
    upload: undefined,
    response: undefined,
    end: undefined,
    error: 1717335988864,
    abort: undefined,
    phases: {
      wait: 1,
      dns: 6,
      tcp: undefined,
      tls: undefined,
      request: undefined,
      firstByte: undefined,
      download: undefined,
      total: 7
    }
}
}

axiuge 发表于 2024-6-3 12:18

JakerPower 发表于 2024-6-2 21:49
出错了
rror copying injection files. Error: File inject.js not found. Note that Nativefier expects...

已更新新版
页: [1] 2
查看完整版本: 利用Nativefier转换成exe的bat-3.0