关于electron-builder的NSIS打包问题

本文详细介绍如何使用NSIS创建自定义安装程序,通过在安装过程中动态配置.ini文件中的store_code和pos_name参数,实现软件安装个性化。适用于内部项目安装流程优化。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

声明:该方法只适合内部使用的项目,想要更好的处理请去学习NSIS
解决的问题:安装包在安装时配置一些基础信息(我这以.ini文件为例)
在项目根目录下创建installer.nsh文件

!include nsDialogs.nsh
!include LogicLib.nsh

#OutFile nsDialogs.exe
#RequestExecutionLevel user
#ShowInstDetails show

Var Dialog
Var /GLOBAL store_code_t
Var /GLOBAL pos_name_t
Var /GLOBAL store_code
Var /GLOBAL pos_name

Page custom pgPageCreate pgPageLeave

Function pgPageCreate

    nsDialogs::Create 1018
    Pop $Dialog

    ${If} $Dialog == error
        Abort
    ${EndIf}

    ${NSD_CreateGroupBox} 10% 10u 80% 100u "设置"
    Pop $0

        ${NSD_CreateLabel} 20% 26u 20% 10u "store_code:"
        Pop $0

        ${NSD_CreateText} 40% 24u 40% 12u "000"
        Pop $store_code_t

        ${NSD_CreateLabel} 20% 40u 20% 10u "pos_name:"
        Pop $0

        ${NSD_CreateText} 40% 38u 40% 12u "001"
        Pop $pos_name_t

    nsDialogs::Show
FunctionEnd

Function PgPageLeave
    ${NSD_GetText} $store_code_t $store_code
    ${NSD_GetText} $pos_name_t $pos_name 
FunctionEnd

Section

SectionEnd
;一下都是官方提供的回调方法
;可以使用NSIS的 MessageBox  进行调试熟悉这些回调,打包有点繁琐
;MessageBox MB_YESNO "真的吗?" IDYES true IDNO false
;true:
 ; DetailPrint "是真的!"
  ;Goto next
;false:
 ; DetailPrint "是假的"

!macro customInstall
  WriteINIStr $INSTDIR\web.ini base store_code $store_code
  WriteINIStr $INSTDIR\web.ini base pos_name $pos_name
!macroend
!macro customHeader
  !system "echo '' > ${BUILD_RESOURCES_DIR}/customHeader"
!macroend

!macro preInit
  ; This macro is inserted at the beginning of the NSIS .OnInit callback
  !system "echo '' > ${BUILD_RESOURCES_DIR}/preInit"
!macroend

!macro customInit
  !system "echo '' > ${BUILD_RESOURCES_DIR}/customInit"
!macroend

!macro customInstallMode
  # set $isForceMachineInstall or $isForceCurrentInstall 
  # to enforce one or the other modes.
!macroend

vue.config.js配置可参考electron-builder官方文档

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值