环境
vue + electron(vue环境加electron)
注意
- 行前面有
;
相当于注释,该行不起作用 - 涉及的路径为当前
.nsi
文件相对目标文件的相对路径
nsi文件内容
此处应用名称使用myproduct
,当前nsi文件位于vue目录最外层,需要打包的文件是dist_electron\win-unpacked\*.*
步骤:
- 替换myproduct.exe为对应名称,替换应用目标路径名称\myproduct。
- 修改第一部分名称 / 企业名称 / 网站
- 修改icon路径
- 修改许可协议路径
- 修改主程序文件路径(这一部分将需要打包的文件夹整个选中)
- 修改删除文件及文件路径
; 该脚本使用 HM VNISEdit 脚本编辑器向导产生
; 安装程序初始定义常量
!define PRODUCT_NAME "myproduct"
!define PRODUCT_VERSION "1.0"
!define PRODUCT_PUBLISHER "企业名称, Inc."
!define PRODUCT_WEB_SITE "http://www.company.com"
!define PRODUCT_DIR_REGKEY "Software\Microsoft\Windows\CurrentVersion\App Paths\myproduct.exe"
!define PRODUCT_UNINST_KEY "Software\Microsoft\Windows\CurrentVersion\Uninstall\${PRODUCT_NAME}"
!define PRODUCT_UNINST_ROOT_KEY "HKLM"
SetCompressor lzma
; ------ MUI 现代界面定义 (1.67 版本以上兼容) ------
!include "MUI.nsh"
; MUI 预定义常量
!define MUI_ABORTWARNING
!define MUI_ICON "dist_electron\favicon.ico"
!define MUI_UNICON "dist_electron\favicon.ico"
; 欢迎页面
!insertmacro MUI_PAGE_WELCOME
; 许可协议页面
!insertmacro MUI_PAGE_LICENSE "dist_electron\win-unpacked\LICENSE.electron.txt"
; 安装过程页面
!insertmacro MUI_PAGE_INSTFILES
; 安装完成页面
;!define MUI_FINISHPAGE_RUN "$INSTDIR\install.bat"
;!define MUI_FINISHPAGE_SHOWREADME "$INSTDIR\*.*"
!insertmacro MUI_PAGE_FINISH
; 安装卸载过程页面
!insertmacro MUI_UNPAGE_INSTFILES
; 安装界面包含的语言设置
!insertmacro MUI_LANGUAGE "SimpChinese"
; 安装预释放文件
!insertmacro MUI_RESERVEFILE_INSTALLOPTIONS
; ------ MUI 现代界面定义结束 ------
Name "${PRODUCT_NAME} ${PRODUCT_VERSION}"
OutFile "myproduct.exe"
InstallDir "$PROGRAMFILES\myproduct"
InstallDirRegKey HKLM "${PRODUCT_DIR_REGKEY}" ""
ShowInstDetails show
ShowUnInstDetails show
BrandingText "myproduct"
Section "主程序(必须)" SEC01
SetOutPath "$INSTDIR"
SetOverwrite ifnewer
File /r "dist_electron\win-unpacked\*.*"
CreateShortCut "$DESKTOP\${PRODUCT_NAME}.lnk" "$INSTDIR\myproduct.exe"
SectionEnd
Section -AdditionalIcons
WriteIniStr "$INSTDIR\${PRODUCT_NAME}.url" "InternetShortcut" "URL" "${PRODUCT_WEB_SITE}"
CreateDirectory "$SMPROGRAMS\myproduct"
CreateShortCut "$SMPROGRAMS\myproduct\Website.lnk" "$INSTDIR\${PRODUCT_NAME}.url"
CreateShortCut "$SMPROGRAMS\myproduct\Uninstall.lnk" "$INSTDIR\uninst.exe"
SectionEnd
Section -Post
WriteUninstaller "$INSTDIR\uninst.exe"
WriteRegStr HKLM "${PRODUCT_DIR_REGKEY}" "" "$INSTDIR\myproduct.exe"
WriteRegStr ${PRODUCT_UNINST_ROOT_KEY} "${PRODUCT_UNINST_KEY}" "DisplayName" "$(^Name)"
WriteRegStr ${PRODUCT_UNINST_ROOT_KEY} "${PRODUCT_UNINST_KEY}" "UninstallString" "$INSTDIR\uninst.exe"
WriteRegStr ${PRODUCT_UNINST_ROOT_KEY} "${PRODUCT_UNINST_KEY}" "DisplayIcon" "$INSTDIR\myproduct.exe"
WriteRegStr ${PRODUCT_UNINST_ROOT_KEY} "${PRODUCT_UNINST_KEY}" "DisplayVersion" "${PRODUCT_VERSION}"
WriteRegStr ${PRODUCT_UNINST_ROOT_KEY} "${PRODUCT_UNINST_KEY}" "URLInfoAbout" "${PRODUCT_WEB_SITE}"
WriteRegStr ${PRODUCT_UNINST_ROOT_KEY} "${PRODUCT_UNINST_KEY}" "Publisher" "${PRODUCT_PUBLISHER}"
SectionEnd
/******************************
* 以下是安装程序的卸载部分 *
******************************/
Section Uninstall
Delete "$INSTDIR\${PRODUCT_NAME}.url"
Delete "$INSTDIR\uninst.exe"
Delete "$INSTDIR\chrome_100_percent.pak"
Delete "$INSTDIR\chrome_200_percent.pak"
Delete "$INSTDIR\d3dcompiler_47.dll"
Delete "$INSTDIR\ffmpeg.dll"
Delete "$INSTDIR\icudtl.dat"
Delete "$INSTDIR\libEGL.dll"
Delete "$INSTDIR\libGLESv2.dll"
Delete "$INSTDIR\LICENSE.electron.txt"
Delete "$INSTDIR\LICENSES.chromium.html"
Delete "$INSTDIR\myproduct.exe"
Delete "$INSTDIR\resources.pak"
Delete "$INSTDIR\snapshot_blob.bin"
Delete "$INSTDIR\v8_context_snapshot.bin"
Delete "$INSTDIR\vk_swiftshader.dll"
Delete "$INSTDIR\vk_swiftshader_icd.json"
Delete "$INSTDIR\vulkan-1.dll"
Delete "$SMPROGRAMS\myproduct\Uninstall.lnk"
Delete "$SMPROGRAMS\myproduct\Website.lnk"
Delete "$DESKTOP\myproduct.lnk"
Delete "$SMPROGRAMS\myproduct\myproduct.lnk"
RMDir "$SMPROGRAMS\myproduct"
RMDir ""
RMDir /r "$INSTDIR\locales"
RMDir /r "$INSTDIR\resources"
RMDir /r "$INSTDIR\swiftshader"
RMDir /r "$INSTDIR\docs"
RMDir "$INSTDIR"
DeleteRegKey ${PRODUCT_UNINST_ROOT_KEY} "${PRODUCT_UNINST_KEY}"
DeleteRegKey HKLM "${PRODUCT_DIR_REGKEY}"
SetAutoClose true
SectionEnd
#-- 根据 NSIS 脚本编辑规则,所有 Function 区段必须放置在 Section 区段之后编写,以避免安装程序出现未可预知的问题。--#
!include x64.nsh
Function .onInit
${If} ${RunningX64}
${EnableX64FSRedirection}
${else}
MessageBox MB_OK "对不起,该应用需要在64位操作系统中运行!"
Abort
${EndIf}
InitPluginsDir
;创建互斥防止重复运行
System::Call 'kernel32::CreateMutexA(i 0, i 0, t "WinSnap_installer") i .r1 ?e'
Pop $R0
StrCmp $R0 0 +3
MessageBox MB_OK|MB_ICONEXCLAMATION "安装向导已经运行!"
Abort
FunctionEnd
Section -
Detailprint '$SYSDIR'
DetailPrint '$WINDIR'
DetailPrint '$PROGRAMFILES'
SectionEnd
Function un.onInit
MessageBox MB_ICONQUESTION|MB_YESNO|MB_DEFBUTTON2 "您确实要完全移除 $(^Name) ,及其所有的组件?" IDYES +2
Abort
FunctionEnd
Function un.onUninstSuccess
HideWindow
MessageBox MB_ICONINFORMATION|MB_OK "$(^Name) 已成功地从您的计算机移除。"
FunctionEnd