1.7.11, is based on
We move to the Electron entry folder. In the case the you are integrating with Angular-CLI following my guide, it would be
electron folder. Then, we run:
npm install -D typescript ts-node
- typescript: Well, this is actually what we want to use.
ts-node: TypeScript execution environment and REPL for node. This will resolver all the
.tsfiles on the fly.
npx tsc --init if you are using npm 5.2+ to create the
tsconfig.json. As is it will work, so we will leave it.
We need to modify how the application runs.
- Create a folder named
src, this will be our development folder.
srcand rename it
index.ts. This is now a Typescript file.
- Create a new
index.jsin the application root, with the following content.
require('ts-node').register(); // This will register the TypeScript compiler require('./src'); // This will load our Typescript application
Now it's time to try, and run
npm start if you are following the integration guide, or
electron . if you don't have the associated script.
This is fine. Because we are using
__dirname as our folder root, now Electron can't find the app source.
Hopefully, the solution is really simple. Just change
__dirname in the
path.join function with
What getAppPath() is? Docs
This is a Electron function that will resolve to the root of the application path.
If everything went fine, you should now see your application running inside Electron.
This is just a guide to show how this work. However, I don't recommend use
ts-node as a production solution. Also, I have not test the
getAppPath function in a bundle application, so it may fail.
We have now a Electron application written in Typescript. It could optimize for production by using a build system, such Webpack. Also, we could target
es6 in the
tsconfig file as Electron main will work fine with es2015.
Uses of native modules are something that seems to have interest of users, so I'll probably made a guide about using them.