I have recently had some struggles with using TypeScript efficiently in my Electron projects. I desire to be able to use TypeScript in both the main process and renderer process with the support for a types.ts file as well.
The only solution I have found as far is using Webpack's TypeScript support with a configuration similar to the following:
const path = require("path");
module.exports = {
mode: "development",
// All electron pages with a source file must be added here
entry: {
page1: "./src/app/pages/page1/index.ts",
page2: "./src/app/pages/page2/index.ts",
page3: "./src/app/pages/page3/index.ts",
},
module: {
rules: [
{
test: /\.ts$/,
use: 'ts-loader',
exclude: /node_modules/,
},
],
},
resolve: {
extensions: ['.ts', '.js'],
},
output: {
filename: '[name].js',
path: path.resolve(__dirname, './src/app/build'),
},
};
Using this however feels a bit hacky to me and significantly slows down my workflow due to me having to run Webpack every time I make changes to the project.
I would like to know, is there a better way of doing this? Thanks in advance.