{"id":1563,"date":"2018-06-08T18:07:00","date_gmt":"2018-06-08T18:07:00","guid":{"rendered":"https:\/\/xplicity.com\/?p=1563"},"modified":"2025-01-03T14:44:20","modified_gmt":"2025-01-03T11:44:20","slug":"part-4-creating-a-desktop-application-with-electron-angular-and-typescript-application-distribution","status":"publish","type":"post","link":"https:\/\/xplicity.com\/part-4-creating-a-desktop-application-with-electron-angular-and-typescript-application-distribution\/","title":{"rendered":"Part 4: Creating a desktop application with Electron, Angular and TypeScript: application distribution"},"content":{"rendered":"\n<p class=\"wp-block-paragraph\">In previous articles (Part 1, Part 2, Part 3) we created a simple Image Gallery desktop application. All this time we\u2019ve been running the application in development mode using electron-build command. While this approach works well for development it will not work for regular users. In this article you will learn how to distribute an Electron application for Windows environments.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">BUILD THE APPLICATION<\/h2>\n\n\n\n<p class=\"wp-block-paragraph\">As you already noticed our application always has\u00a0DevTools console opened by default when you start the application.<\/p>\n\n\n<div class=\"wp-block-image\">\n<figure class=\"aligncenter size-full\"><img loading=\"lazy\" decoding=\"async\" width=\"600\" height=\"153\" src=\"https:\/\/xplicity.com\/wp-content\/uploads\/2023\/07\/img_5dadb08d3ec16.png\" alt=\"\" class=\"wp-image-1566\" srcset=\"https:\/\/xplicity.com\/wp-content\/uploads\/2023\/07\/img_5dadb08d3ec16.png 600w, https:\/\/xplicity.com\/wp-content\/uploads\/2023\/07\/img_5dadb08d3ec16-300x77.png 300w\" sizes=\"auto, (max-width: 600px) 100vw, 600px\" \/><\/figure>\n<\/div>\n\n\n<p class=\"wp-block-paragraph\">DevTools are useful during development process, but we do not want the&nbsp;end user to see this console, so it\u2019s a good idea to disable it. To do that comment out DevTools opening line in the&nbsp;<strong>electron\/main.ts<\/strong>&nbsp;file:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>\/\/ mainWindow.webContents.openDevTools();<\/code><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">Compile the application using the production configuration:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>npm run electron-build-prod<\/code><\/pre>\n\n\n\n<h2 class=\"wp-block-heading\">DOWNLOAD AND EXTRACT ELECTRON\u2019S PREBUILT BINARIES<\/h2>\n\n\n\n<p class=\"wp-block-paragraph\">Download&nbsp;<a href=\"https:\/\/github.com\/electron\/electron\/releases\" target=\"_blank\" rel=\"noreferrer noopener\">Electron\u2019s prebuilt binaries<\/a>. Check what version of the electron package you have in the&nbsp;<strong>package.json<\/strong>&nbsp;file and chose correct version from the list. We will use Electron\u2019s binaries of version&nbsp;<strong>1.8.x<\/strong>&nbsp;for&nbsp;<strong>Windows x64<\/strong>: e.g.&nbsp;<strong>electron-v1.8.7-win32-x64.zip<\/strong>.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">Create&nbsp;<strong>bin<\/strong>&nbsp;folder in the root directory of the project. To prevent accidental commit of this folder, add this folder (<strong>\/bin<\/strong>) to the root directory\u2019s&nbsp;<strong>.gitignore<\/strong>&nbsp;file:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code># compiled output\n\/dist\n\/dist-server\n\/tmp\n\/out-tsc\n\/bin<\/code><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">Extract the downloaded zip file of Electron\u2019s pre-build binaries to the&nbsp;<strong>bin<\/strong>&nbsp;folder.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">COPY COMPILED APPLICATION TO ELECTRON\u2019S RESOURCES DIRECTORY<\/h2>\n\n\n\n<p class=\"wp-block-paragraph\">Create\u00a0<strong>app<\/strong>\u00a0folder in the\u00a0<strong>bin\/resources<\/strong>\u00a0folder. Copy\u00a0<strong>dist<\/strong>\u00a0folder\u2019s contents to the\u00a0<strong>bin\/resources\/app<\/strong>\u00a0folder.<\/p>\n\n\n<div class=\"wp-block-image\">\n<figure class=\"aligncenter size-full\"><img loading=\"lazy\" decoding=\"async\" width=\"800\" height=\"330\" src=\"https:\/\/xplicity.com\/wp-content\/uploads\/2023\/07\/img_5dadb09ad5363.png\" alt=\"\" class=\"wp-image-1568\" srcset=\"https:\/\/xplicity.com\/wp-content\/uploads\/2023\/07\/img_5dadb09ad5363.png 800w, https:\/\/xplicity.com\/wp-content\/uploads\/2023\/07\/img_5dadb09ad5363-300x124.png 300w, https:\/\/xplicity.com\/wp-content\/uploads\/2023\/07\/img_5dadb09ad5363-768x317.png 768w\" sizes=\"auto, (max-width: 800px) 100vw, 800px\" \/><\/figure>\n<\/div>\n\n\n<h2 class=\"wp-block-heading\">CREATE PACKAGE.JSON FILE<\/h2>\n\n\n\n<p class=\"wp-block-paragraph\">Electron requires&nbsp;<strong>package.json<\/strong>&nbsp;file to be placed inside&nbsp;<strong>bin\/resources\/app<\/strong>&nbsp;folder. This file is different from the&nbsp;<strong>package.json<\/strong>&nbsp;file which is located in the root folder of the source code. Do not copy the&nbsp;<strong>package.json<\/strong>&nbsp;file from the root folder of the source code to the&nbsp;<strong>bin\/resources\/app<\/strong>. This will result into including all Angular dependencies (more than 400 MB) alongside with your app.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">Let\u2019s create a simple&nbsp;<strong>package.json<\/strong>&nbsp;file:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>{\n  \"name\": \"ng-electron-app\",\n  \"version\": \"0.0.0\",\n  \"license\": \"MIT\",\n  \"main\": \"main.js\",\n  \"private\": true,\n  \"dependencies\": {}\n}<\/code><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">It specifies application name, version, license type, entry point (<strong>main<\/strong>), npm publishing setting (<strong>private<\/strong>) and dependencies. In our case dependencies array is empty. But if you used any additional libraries in the Electron\u2019s backend code you must add these dependencies to this array and run&nbsp;<strong>npm install<\/strong>&nbsp;command in the&nbsp;<strong>bin\/resources\/app<\/strong>&nbsp;folder.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">Execute\u00a0<strong>bin\/electron.exe<\/strong>\u00a0file, it should open your application.<\/p>\n\n\n<div class=\"wp-block-image\">\n<figure class=\"aligncenter size-full\"><img loading=\"lazy\" decoding=\"async\" width=\"600\" height=\"415\" src=\"https:\/\/xplicity.com\/wp-content\/uploads\/2023\/07\/img_5dadb0a72c92e.png\" alt=\"\" class=\"wp-image-1569\" srcset=\"https:\/\/xplicity.com\/wp-content\/uploads\/2023\/07\/img_5dadb0a72c92e.png 600w, https:\/\/xplicity.com\/wp-content\/uploads\/2023\/07\/img_5dadb0a72c92e-300x208.png 300w\" sizes=\"auto, (max-width: 600px) 100vw, 600px\" \/><\/figure>\n<\/div>\n\n\n<h2 class=\"wp-block-heading\">REBRANDING<\/h2>\n\n\n\n<p class=\"wp-block-paragraph\">Electron\u2019s prebuilt binaries provides&nbsp;<strong>electron.exe<\/strong>&nbsp;file which is main executable for the application. We do not want our application\u2019s process to be called&nbsp;<strong>electron.exe<\/strong>. Navigate to&nbsp;<strong>bin<\/strong>&nbsp;folder and rename&nbsp;<strong>electron.exe<\/strong>&nbsp;to&nbsp;<strong>nge-image-viewer.exe<\/strong>.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">Executable files usually contain icon and information about the product \u2013 name, company name, version, copyright, etc. By default, in the\u00a0<strong>electron.exe<\/strong>\u00a0file\u00a0(now\u00a0<strong>nge-image-viewer.exe<\/strong>, because we\u2019ve just renamed it) this data is related to Electron product and GitHub organization, and it has Electron\u2019s logo as the icon. You can see this data in file\u2019s Properties dialog:<\/p>\n\n\n<div class=\"wp-block-image\">\n<figure class=\"aligncenter size-full\"><img loading=\"lazy\" decoding=\"async\" width=\"363\" height=\"504\" src=\"https:\/\/xplicity.com\/wp-content\/uploads\/2023\/07\/img_5dadb0b2d7b56.png\" alt=\"\" class=\"wp-image-1570\" srcset=\"https:\/\/xplicity.com\/wp-content\/uploads\/2023\/07\/img_5dadb0b2d7b56.png 363w, https:\/\/xplicity.com\/wp-content\/uploads\/2023\/07\/img_5dadb0b2d7b56-216x300.png 216w\" sizes=\"auto, (max-width: 363px) 100vw, 363px\" \/><\/figure>\n<\/div>\n\n\n<p class=\"wp-block-paragraph\">You can modify executable\u2019s metadata and change its icon using&nbsp;<a href=\"https:\/\/github.com\/electron\/rcedit\" target=\"_blank\" rel=\"noreferrer noopener\">Rcedit<\/a>&nbsp;tool. Download&nbsp;the latest version of&nbsp;<a href=\"https:\/\/github.com\/electron\/rcedit\/releases\" target=\"_blank\" rel=\"noreferrer noopener\">Rcedit executable<\/a>.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">With Rcedit\u2019s&nbsp;<strong>\u2013set-version-string<\/strong>&nbsp;argument you can modify product name, company name, copyright, original file name, file info description and other properties. The full list of supported properties is described in the&nbsp;<a href=\"https:\/\/msdn.microsoft.com\/en-us\/library\/windows\/desktop\/aa381058(v=vs.85).aspx\" target=\"_blank\" rel=\"noreferrer noopener\">MSDN documentation<\/a>&nbsp;(in the&nbsp;<strong>string-name<\/strong>&nbsp;parameter\u2019s documentation part). Using&nbsp;<strong>\u2013set-product-version<\/strong>&nbsp;argument you can change the product\u2019s version property. And&nbsp;<strong>\u2013set-icon<\/strong>&nbsp;argument is responsible for changing the icon of the executable file.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">Make sure the&nbsp;<strong>nge-image-viewer.exe<\/strong>&nbsp;process is not running and run the following commands to change executable\u2019s metadata and icon:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>rcedit-x64.exe \"C:\\projects\\ng-electron-app\\bin\\nge-image-viewer.exe\" --get-version-string \"ProductName\" \"Electron\"\n\nrcedit-x64.exe \"C:\\projects\\ng-electron-app\\bin\\nge-image-viewer.exe\" --set-version-string \"ProductName\" \"NGE Image Viewer\"\n\nrcedit-x64.exe \"C:\\projects\\ng-electron-app\\bin\\nge-image-viewer.exe\" --set-version-string \"CompanyName\" \"Xplicity\"\n\nrcedit-x64.exe \"C:\\projects\\ng-electron-app\\bin\\nge-image-viewer.exe\" --set-product-version \"1.0\"\n\nrcedit-x64.exe \"C:\\projects\\ng-electron-app\\bin\\nge-image-viewer.exe\" --set-version-string \"LegalCopyright\" \"Copyright (c) 2018 Xplicity. All rights reserved.\"\n\nrcedit-x64.exe \"C:\\projects\\ng-electron-app\\bin\\nge-image-viewer.exe\" --set-version-string \"OriginalFilename\" \"nge-image-viewer.exe\"\n\nrcedit-x64.exe \"C:\\projects\\ng-electron-app\\bin\\nge-image-viewer.exe\" --set-version-string \"FileDescription\" \"NGE Image Viewer\"\n\nrcedit-x64.exe \"C:\\projects\\ng-electron-app\\bin\\nge-image-viewer.exe\" --set-icon \"C:\\Users\\Andrius\\Downloads\\x_icon.ico\"<\/code><\/pre>\n\n\n<div class=\"wp-block-image\">\n<figure class=\"aligncenter size-full\"><img loading=\"lazy\" decoding=\"async\" width=\"600\" height=\"366\" src=\"https:\/\/xplicity.com\/wp-content\/uploads\/2023\/07\/img_5dadb0bf3996c.png\" alt=\"\" class=\"wp-image-1571\" srcset=\"https:\/\/xplicity.com\/wp-content\/uploads\/2023\/07\/img_5dadb0bf3996c.png 600w, https:\/\/xplicity.com\/wp-content\/uploads\/2023\/07\/img_5dadb0bf3996c-300x183.png 300w\" sizes=\"auto, (max-width: 600px) 100vw, 600px\" \/><\/figure>\n<\/div>\n\n\n<p class=\"wp-block-paragraph\">Don\u2019t forget to modify paths to match your existing paths. If you use x86 version of the Rcedit tool, use\u00a0<strong>rcedit-x86.exe<\/strong>\u00a0instead of\u00a0<strong>rcedit-x64.exe<\/strong>\u00a0in the commands.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">Navigate to file, open file properties and check the results.<\/p>\n\n\n<div class=\"wp-block-image\">\n<figure class=\"aligncenter size-full\"><img loading=\"lazy\" decoding=\"async\" width=\"600\" height=\"477\" src=\"https:\/\/xplicity.com\/wp-content\/uploads\/2023\/07\/img_5dadb0d7549c7.png\" alt=\"\" class=\"wp-image-1572\" srcset=\"https:\/\/xplicity.com\/wp-content\/uploads\/2023\/07\/img_5dadb0d7549c7.png 600w, https:\/\/xplicity.com\/wp-content\/uploads\/2023\/07\/img_5dadb0d7549c7-300x239.png 300w\" sizes=\"auto, (max-width: 600px) 100vw, 600px\" \/><\/figure>\n<\/div>\n\n<div class=\"wp-block-image\">\n<figure class=\"aligncenter size-full\"><img loading=\"lazy\" decoding=\"async\" width=\"363\" height=\"509\" src=\"https:\/\/xplicity.com\/wp-content\/uploads\/2023\/07\/img_5dadb0e098985.png\" alt=\"\" class=\"wp-image-1573\" srcset=\"https:\/\/xplicity.com\/wp-content\/uploads\/2023\/07\/img_5dadb0e098985.png 363w, https:\/\/xplicity.com\/wp-content\/uploads\/2023\/07\/img_5dadb0e098985-214x300.png 214w\" sizes=\"auto, (max-width: 363px) 100vw, 363px\" \/><\/figure>\n<\/div>\n\n\n<h2 class=\"wp-block-heading\">CONCLUSION<\/h2>\n\n\n\n<p class=\"wp-block-paragraph\">After all steps that we\u2019ve made,&nbsp;<strong>bin<\/strong>&nbsp;folder contains files that can be distributed. The&nbsp;<strong>nge-image-viewer.exe<\/strong>&nbsp;is the application\u2019s executable, which has the icon and product information set. From this point, you can build an installer or just create a zip file from&nbsp;<strong>bin<\/strong>&nbsp;folder\u2019s contents. In order to update the application\u2019s distributable files it is enough to clean up the&nbsp;<strong>bin\/resources\/app<\/strong>&nbsp;folder (delete everything except&nbsp;<strong>package.json<\/strong>), run&nbsp;<strong>npm install<\/strong>&nbsp;command if needed, and&nbsp;copy the&nbsp;<strong>dist<\/strong>&nbsp;folder\u2019s contents to the&nbsp;<strong>bin\/resources\/app<\/strong>&nbsp;folder. You can automate these steps by adding additional custom commands to your application source code root folder\u2019s&nbsp;<strong>package.json<\/strong>&nbsp;file.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>In previous articles (Part 1, Part 2, Part 3) we created a simple Image Gallery desktop application. All this time we\u2019ve been running the application in development mode using electron-build command. While this approach works well for development it will not work for regular users. In this article you will learn how to distribute an [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":1564,"comment_status":"closed","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[11],"tags":[],"class_list":["post-1563","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-blog"],"acf":[],"_links":{"self":[{"href":"https:\/\/xplicity.com\/wp-json\/wp\/v2\/posts\/1563","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/xplicity.com\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/xplicity.com\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/xplicity.com\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/xplicity.com\/wp-json\/wp\/v2\/comments?post=1563"}],"version-history":[{"count":3,"href":"https:\/\/xplicity.com\/wp-json\/wp\/v2\/posts\/1563\/revisions"}],"predecessor-version":[{"id":1574,"href":"https:\/\/xplicity.com\/wp-json\/wp\/v2\/posts\/1563\/revisions\/1574"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/xplicity.com\/wp-json\/wp\/v2\/media\/1564"}],"wp:attachment":[{"href":"https:\/\/xplicity.com\/wp-json\/wp\/v2\/media?parent=1563"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/xplicity.com\/wp-json\/wp\/v2\/categories?post=1563"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/xplicity.com\/wp-json\/wp\/v2\/tags?post=1563"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}