electron-userland / electron-compile

DEPRECATED: Electron supporting package to compile JS and CSS in Electron applications
1.01k stars 99 forks source link

tsconfig.json vs. .compilerrc? #308

Open starkos opened 6 years ago

starkos commented 6 years ago

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 commented 6 years ago

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 commented 6 years ago

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 commented 6 years ago

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