electron-compile
electron-compile copied to clipboard
tsconfig.json vs. .compilerrc?
A request for clarification: how do tsconfig.json and .compilerrc relate to each other, if at all? Based on my own experiments, it seems like I have to duplicate every setting between the two files; is there a way to link the two?
(Using electron-forge, if it matters.)
Hi @starkos,
I am not 100% sure about how to answer your question as I am not an expert at this, just a passerby, but in my experimentation the .compilerrc.json file is basically just JSON settings that get handed to the various compilers. Note that electron-compile is trying to solve a very specific problem:
- You request
such-and-so.tsfrom your Electron application, while running - The
electron-compilewatcher sees this, and readssuch-and-so.tsfrom the disk. - It determines if it is binary-identical with any previously compiled files: if so, it serves the previously compiled output.
- Otherwise it compiles it to JS and serves it: it still has the
.tsextension (there is no helping that) but it is served withContent-Type: application/json. - Finally to whatever extent possible that set of "previously compiled files" is prepopulated at build-time.
So it needs these settings in order to successfully accomplish steps 4 and 5.
There is therefore a chance that you do not need tsconfig.json at all: you would presumably only need tsconfig.json if you are running tsc but you are not running tsc yourself in the above workflow.
There is also a chance that this approach is overkill. You may want to simply do the conventional thing: have a src/ folder which contains your TypeScript, first compile to a dist/ folder which contains your JS, then run electron-forge to build the remaining app. In this case, .compilerrc's section for the TypeScript compiler becomes pointless to you, you just have to make sure that Babel is properly compiling TypeScript's output to something the browser can use.
Thanks @ChrisDrostUSE…I need tsconfig.json to provide the project settings for VS Code. I'd like to keep electron-compile in place, as I'm trying to do things the Electron Forge Way™️ if I can.
If you leave the .compilerc.json section for typescript blank,
does it use your tsconfig.json settings?
Because that may be a solution.
If it doesn't,
you're maybe stuck.
What you might have to do,
is to assemble it pre-build
with some make-compilerc.js file,
require('fs').writeFileSync(
'.compilerc.json',
JSON.stringify({
'application/typescript': require('./tsconfig'),
whateverElse: 'whatever else'
})
);
Then in package.json,
"scripts": {"build": "electron-forge build ."}
becomes instead,
"build": "node make-compilerc.js && electron-forge ."