adopted-ember-addons / ember-electron

:zap: Build, test, compile and package desktop apps with Ember and Electron
https://ember-electron.js.org/
Other
805 stars 109 forks source link

Q: Compatibility with typescript #1495

Open basz opened 1 year ago

basz commented 1 year ago

Hi,

I have an working application that I want to convert to typescript.

Looking at https://github.com/electron/forge there is a typescript template that indeed runs when being a stand alone electron app.

However in ember-electron this does not seem to work... I think becuase ember-electron run forge via its 'api' and therefore uses ts config from the enclosing ember app.

This works

cd electron-app
yarn electron-forge start

But this will fail;

ember electron
Starting Electron...
Failed to load: /..../electron-app/forge.config.ts
Cannot use import statement outside a module

Is this even possible? Perhaps any example repositories?

RobbieTheWagner commented 1 year ago

@basz I use TypeScript for the Ember side, but not the Electron side.

basz commented 1 year ago

yeah. now i know why... pita... anyway a bit further

added this to the root tsconfig.json

"target": "ES2020",
"module": "commonjs",

App compiles, and starts. I see a window with

Compiled with problems:
×
ERROR
Module not found: Error: Can't resolve './src/renderer.ts' in '/path/to/app'

Soo it loads the main entry point. Feel like I am really close...

basz commented 1 year ago

Yes. I now have the template typescript app running as an ember-electron application! Runs as yarn electron-forge start and as ember electron

trick was to use __dirname inside the forge.config.ts

entryPoints: [
          {
            html: __dirname + '/src/index.html',
            js: __dirname + '/src/renderer.ts',
            name: 'main_window',
            preload: {
              js: __dirname + '/src/preload.ts',
            },
          },
        ],
bendemboski commented 1 year ago

@basz this is awesome! I've long wanted to figure out how to start writing main process code in typescript. Thanks so much for pioneering! Would you be willing to write up some documentation, like a little how-to or something? I'm happy to support in any way.

basz commented 1 year ago

Yes! Ping me if I forget

basz commented 1 year ago

https://bushbaby.nl/ember-electron-and-typescript/

basz commented 1 year ago

not sure if that setup is complete. Although it runs with typescript it is also webpack'ed. That is a whole new beast to configure. The "old" method of loading file://path/to/app/emebr-dist/index.html' seems to work, but the template starter actually uses real url'shttp://localhost:3000/main_window`. These should have the ember app packed into it I'm guessing. Unfortunately I don't know how to to that properly :-/

basz commented 1 year ago

@bendemboski any thoughts?

bendemboski commented 1 year ago

Sorry, I don't really, I haven't had a chance to dig into this at all

basz commented 1 year ago

for any one that needs a starting point. https://github.com/basz/ember-electron-app/

RobbieTheWagner commented 2 months ago

@basz is this something you could write up in our official documentation perhaps?

basz commented 2 months ago

Ai. That's been while. Not sure if I can afford the time to dig back into the intricacies. Sorry.