How would you adjust the following script to allow electron main process to use Typescript with ts-node?
"scripts": {
"shell": "cross-env NODE_ENV=development electron ts-node ./app/main.ts"
}
How would you adjust the following script to allow electron main process to use Typescript with ts-node?
"scripts": {
"shell": "cross-env NODE_ENV=development electron ts-node ./app/main.ts"
}
cross-env NODE_ENV=development electron -r ts-node/register ./app/main.ts
https://github.com/TypeStrong/ts-node#programmatic
You can require ts-node and register the loader for future requires by using require('ts-node').register({ /* options */ }). You can also use file shortcuts - node -r ts-node/register or node -r ts-node/register/transpile-only - depending on your preferences.
While using electron -r ts-node/register
works for simple cases, you can also have your script point to a bootscript JavaScript file that just does this:
require('ts-node').register()
require('./app/main')
The benefit of doing this is that you can specify ts-node options. Necessary for e.g. monorepos, where you might to something like require('ts-node').register({ project: './app/tsconfig.json' })
.
See the ts-node docs for options that can be specified: https://typestrong.org/ts-node/api/interfaces/RegisterOptions.html