NSIS
The top-level nsis key contains set of options instructing electron-builder on how it should build NSIS target (default target for Windows).
These options also applicable for Web installer, use top-level nsisWeb key.
-
oneClick=trueBoolean - Whether to create one-click installer or assisted. -
perMachine=falseBoolean - Whether to show install mode installer page (choice per-machine or per-user) for assisted installer. Or whether installation always per all users (per-machine).If
oneClickistrue(default): Whether to install per all users (per-machine).If
oneClickisfalseandperMachineistrue: no install mode installer page, always install per-machine.If
oneClickisfalseandperMachineisfalse(default): install mode installer page. -
selectPerMachineByDefault=falseBoolean - Whether to set per-machine or per-user installation as default selection on the install mode installer page. -
allowElevation=trueBoolean - assisted installer only. Allow requesting for elevation. If false, user will have to restart installer with elevated permissions. -
allowToChangeInstallationDirectory=falseBoolean - assisted installer only. Whether to allow user to change installation directory. -
removeDefaultUninstallWelcomePage=falseBoolean - assisted installer only. remove the default uninstall welcome page.
installerIconString | “undefined” - The path to installer icon, relative to the build resources or to the project directory. Defaults tobuild/installerIcon.icoor application icon.uninstallerIconString | “undefined” - The path to uninstaller icon, relative to the build resources or to the project directory. Defaults tobuild/uninstallerIcon.icoor application icon.installerHeader=build/installerHeader.bmpString | “undefined” - assisted installer only.MUI_HEADERIMAGE, relative to the build resources or to the project directory.installerHeaderIconString | “undefined” - one-click installer only. The path to header icon (above the progress bar), relative to the build resources or to the project directory. Defaults tobuild/installerHeaderIcon.icoor application icon.installerSidebarString | “undefined” - assisted installer only.MUI_WELCOMEFINISHPAGE_BITMAP, relative to the build resources or to the project directory. Defaults tobuild/installerSidebar.bmpor${NSISDIR}\\Contrib\\Graphics\\Wizard\\nsis3-metro.bmp. Image size 164 × 314 pixels.uninstallerSidebarString | “undefined” - assisted installer only.MUI_UNWELCOMEFINISHPAGE_BITMAP, relative to the build resources or to the project directory. Defaults toinstallerSidebaroption orbuild/uninstallerSidebar.bmporbuild/installerSidebar.bmpor${NSISDIR}\\Contrib\\Graphics\\Wizard\\nsis3-metro.bmpuninstallDisplayName=${productName} ${version}String - The uninstaller display name in the control panel.
-
includeString | “undefined” - The path to NSIS include script to customize installer. Defaults tobuild/installer.nsh. See Custom NSIS script. -
scriptString | “undefined” - The path to NSIS script to customize installer. Defaults tobuild/installer.nsi. See Custom NSIS script. -
licenseString | “undefined” - The path to EULA license file. Defaults tolicense.txtoreula.txt(or uppercase variants). In addition totxt,rtfandhtmlsupported (don’t forget to usetarget="_blank"for links).Multiple license files in different languages are supported — use lang postfix (e.g.
_de,_ru). For example, create fileslicense_de.txtandlicense_en.txtin the build resources. If OS language is german,license_de.txtwill be displayed. See map of language code to name.Appropriate license file will be selected by user OS language.
-
artifactNameString | “undefined” - The artifact file name template. Defaults to${productName} Setup ${version}.${ext}. -
deleteAppDataOnUninstall=falseBoolean - one-click installer only. Whether to delete app data on uninstall.
displayLanguageSelector=falseBoolean - Whether to display a language selection dialog. Not recommended (by default will be detected using OS language).installerLanguagesArray<String> | String | “undefined” - The installer languages (e.g.en_US,de_DE). Change only if you understand what do you do and for what.languageString | “undefined” - LCID Dec, defaults to1033(English - United States).multiLanguageInstallerBoolean - Whether to create multi-language installer. Defaults tounicodeoption value.packElevateHelper=trueBoolean - Whether to pack the elevate executable (required for electron-updater if per-machine installer used or can be used in the future). Ignored ifperMachineis set totrue.preCompressedFileExtensions=[".avi", ".mov", ".m4v", ".mp4", ".m4p", ".qt", ".mkv", ".webm", ".vmdk"]Array<String> | String | “undefined” - The file extension of files that will be not compressed. Applicable only forextraResourcesandextraFilesfiles.unicode=trueBoolean - Whether to create Unicode installer.guidString | “undefined” - See GUID vs Application Name.warningsAsErrors=trueBoolean - IfwarningsAsErrorsistrue(default): NSIS will treat warnings as errors. IfwarningsAsErrorsisfalse: NSIS will allow warnings.customNsisBinarymodule:app-builder-lib/out/targets/nsis/nsisOptions.CustomNsisBinary | “undefined” - Allows you to provide your ownmakensis, such as one with support for debug logging via LogSet and LogText. (Logging also requires optiondebugLogging = true)runAfterFinish=trueBoolean - Whether to run the installed application after finish. For assisted installer corresponding checkbox will be removed.
createDesktopShortcut=trueBoolean | “always” - Whether to create desktop shortcut. Set toalwaysif to recreate also on reinstall (even if removed by user).createStartMenuShortcut=trueBoolean - Whether to create start menu shortcut.menuCategory=falseBoolean | String - Whether to create submenu for start menu shortcut and program files directory. Iftrue, company name will be used. Or string value.shortcutNameString | “undefined” - The name that will be used for all shortcuts. Defaults to the application name.
Inherited from TargetSpecificOptions:
artifactNameString | “undefined” - The artifact file name template.publishThe publish options.
Unicode enabled by default. Large strings are supported (maximum string length of 8192 bytes instead of the default of 1024 bytes).
32 bit + 64 bit¶
If you build both ia32 and x64 arch (--x64 --ia32), you in any case get one installer. Appropriate arch will be installed automatically.
The same applied to web installer (nsis-web target).
Web Installer¶
To build web installer, set target to nsis-web. Web Installer automatically detects OS architecture and downloads corresponding package file. So, user don’t need to guess what installer to download and in the same time you don’t bundle package files for all architectures in the one installer (as in case of default nsis target). It doesn’t matter for common Electron application (due to superb LZMA compression, size difference is acceptable), but if your application is huge, Web Installer is a solution.
To customize web installer, use the top-level nsisWeb key (not nsis).
If for some reasons web installer cannot download (antivirus, offline):
- Download package file into the same directory where installer located. It will be detected automatically and used instead of downloading from the Internet. Please note — only original package file is allowed (checksum is checked).
- Specify any local package file using
--package-file=path_to_file.
Custom NSIS script¶
Two options are available — include and script. script allows you to provide completely different NSIS script. For most cases it is not required as you need only to customise some aspects, but still use well-tested and maintained default NSIS script. So, include is recommended.
Keep in mind — if you customize NSIS script, you should always state about it in the issue reports. And don’t expect that your issue will be resolved.
- Add file
build/installer.nsh. -
Define wanted macro to customise:
customHeader,preInit,customInit,customUnInit,customInstall,customUnInstall,customRemoveFiles,customInstallMode,customWelcomePage,customUnWelcomePage.Example
!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 customInstall !system "echo '' > ${BUILD_RESOURCES_DIR}/customInstall" !macroend !macro customInstallMode # set $isForceMachineInstall or $isForceCurrentInstall # to enforce one or the other modes. !macroend !macro customWelcomePage # Welcome Page is not added by default for installer. !insertMacro MUI_PAGE_WELCOME !macroend !macro customUnWelcomePage !define MUI_WELCOMEPAGE_TITLE "custom title for uninstaller welcome page" !define MUI_WELCOMEPAGE_TEXT "custom text for uninstaller welcome page $\r$\n more" !insertmacro MUI_UNPAGE_WELCOME !macroend -
BUILD_RESOURCES_DIRandPROJECT_DIRare defined. buildis added asaddincludedir(i.e. you don’t need to useBUILD_RESOURCES_DIRto include files).build/x86-unicodeandbuild/x86-ansiare added asaddplugindir.- File associations macro
registerFileAssociationsandunregisterFileAssociationsare still defined. - All other electron-builder specific flags (e.g.
ONE_CLICK) are still defined.
If you want to include additional resources for use during installation, such as scripts or additional installers, you can place them in the build directory and include them with File. For example, to include and run extramsi.msi during installation, place it in the build directory and use the following:
!macro customInstall
File /oname=$PLUGINSDIR\extramsi.msi "${BUILD_RESOURCES_DIR}\extramsi.msi"
ExecWait '"msiexec" /i "$PLUGINSDIR\extramsi.msi" /passive'
!macroend
Is there a way to call just when the app is installed (or uninstalled) manually and not on update?
Use ${isUpdated}.
${ifNot} ${isUpdated}
# your code
${endIf}
GUID vs Application Name¶
Windows requires to use registry keys (e.g. INSTALL/UNINSTALL info). Squirrel.Windows simply uses application name as key. But it is not robust — Google can use key Google Chrome SxS, because it is a Google.
So, it is better to use GUID.
You are not forced to explicitly specify it — name-based UUID v5 will be generated from your appId or name.
It means that you should not change appId once your application in use (or name if appId was not set). Application product name (title) or description can be safely changed.
You can explicitly set guid using option nsis.guid, but it is not recommended — consider using appId.
It is also important to set the Application User Model ID (AUMID) to the appId of the application, in order for notifications on Windows 8/8.1 to function and for Window 10 notifications to display the app icon within the notifications by default. The AUMID should be set within the Main process and before any BrowserWindows have been opened, it is normally the first piece of code executed: app.setAppUserModelId(appId)
Portable¶
To build portable app, set target to portable (or pass --win portable).
For portable app, following environment variables are available:
PORTABLE_EXECUTABLE_FILE- path to the portable executable.PORTABLE_EXECUTABLE_DIR- directory where the portable executable is located.PORTABLE_EXECUTABLE_APP_FILENAME- sanitized app name to use in file paths.
Common Questions¶
How do change the default installation directory to custom?
It is very specific requirement. Do not do if you are not sure. Add custom macro:
!macro preInit
SetRegView 64
WriteRegExpandStr HKLM "${INSTALL_REGISTRY_KEY}" InstallLocation "C:\MyApp"
WriteRegExpandStr HKCU "${INSTALL_REGISTRY_KEY}" InstallLocation "C:\MyApp"
SetRegView 32
WriteRegExpandStr HKLM "${INSTALL_REGISTRY_KEY}" InstallLocation "C:\MyApp"
WriteRegExpandStr HKCU "${INSTALL_REGISTRY_KEY}" InstallLocation "C:\MyApp"
!macroend
Is it possible to made single installer that will allow configuring user/machine installation?
Yes, you need to switch to assisted installer (not default one-click).
package.json
"build": {
"nsis": {
"oneClick": false
}
}
nsis:
oneClick: false