Skip to content
This repository has been archived by the owner on Oct 1, 2020. It is now read-only.

tsconfig.json vs. .compilerrc? #308

Open
starkos opened this issue Jul 31, 2018 · 3 comments
Open

tsconfig.json vs. .compilerrc? #308

starkos opened this issue Jul 31, 2018 · 3 comments

Comments

@starkos
Copy link

starkos commented Jul 31, 2018

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.)

@ChrisDrostUSE
Copy link

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:

  1. You request such-and-so.ts from your Electron application, while running
  2. The electron-compile watcher sees this, and reads such-and-so.ts from the disk.
  3. It determines if it is binary-identical with any previously compiled files: if so, it serves the previously compiled output.
  4. Otherwise it compiles it to JS and serves it: it still has the .ts extension (there is no helping that) but it is served with Content-Type: application/json.
  5. 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.

@starkos
Copy link
Author

starkos commented Aug 2, 2018

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.

@ChrisDrostUSE
Copy link

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 ."

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants