DEV Community

Discussion on: Create Your First React Desktop Application in Electron with Hot-Reload

Collapse
 
jrpickhardt profile image
Jeff Pickhardt

So many questions:
1 - What's the point of serviceWorker.unregister()?
2 - There's no TypeScript, right? I downloaded the repo and don't see TS
3 - What's the point of running a development server, then loading the app through the dev server? I am new to Electron but thought you're supposed to have it all contained in some code the Electron app just presents by itself.
4 - What would you run to build it as a production-ready app you could send to others? (I'm curious how this relates to 3 with there being a development server)

Collapse
 
pkinnucan profile image
Paul Kinnucan • Edited
  1. Don't know but the comment in the file provides a link to an explanation.
  2. CRA supports TypeScript but you have to install the typescript compiler and change extensions from js to tsx. Also, if you want to use TypeScript in your Jest tests, you need to install the Jest type definitions package: @types/jest
  3. The development server speeds development by rendering changes to the source without requiring you to restart electron. In production mode, the start.js file loads the browser window with the index.html file that is packaged into the installer generated by electron-build.
  4. Unfortunately, the instructions stop short of explaining how to use electron-build to package your app into an installer that you can distribute to users. To do, this you must add the following scripts to your package.json file:

    "pack": "electron-builder --dir",
    "dist": "electron-builder"

You must also move electron from the dependencies property in your package.json to the devDependencies property.

One other thing, if you want to follow the suggestion about how to avoid popping the dev server up in a browser, you must install cross-env.

Collapse
 
johannel00 profile image
johannel00

I was getting errors about the entry point. I added this to the "build:" property in the package.json file:

    "files": [
      "node_modules/**/*",
      {
        "from": "src",
        "to": "build",
        "filter": "**/*"
      }
    ]

Here is the source to the comment that helped.