Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Transpiling main process #15

Open
aidan-rypens opened this issue Oct 8, 2020 · 10 comments
Open

Transpiling main process #15

aidan-rypens opened this issue Oct 8, 2020 · 10 comments

Comments

@aidan-rypens
Copy link

Why does it make no sense to transpile your main process files?

Just a question!

@sindresorhus
Copy link
Owner

Because Electron already supports the latest JavaScript features.

@aidan-rypens
Copy link
Author

Ah. I think I didn't understand it correctly. So you meant like having something as Babel that writes out your Electron js files in order to support a lower ES?

But to have the Electron files written in Typescript to transpile; that is okay to do? It works with using the typescript built in transpiler.

Just making sure that I don't do something that I shouldn't! I'm sorry if I didn't get what you meant correctly.

@sindresorhus
Copy link
Owner

So you meant like having something as Babel that writes out your Electron js files in order to support a lower ES?

Yes.

But to have the Electron files written in Typescript to transpile; that is okay to do? It works with using the typescript built in transpiler.

That would be the same case.

@sindresorhus
Copy link
Owner

Looking more into this, I'm not actually sure anymore why it wouldn't work when transpiled... I should have written some notes to myself about this. If it works fine for you, then great. I'll keep this open until I have time to look more into this and potentially remove that readme note.

@aidan-rypens
Copy link
Author

It works for me, so not a problem here. Thanks!

@kroko
Copy link

kroko commented Jan 19, 2021

@AidanRRR it makes sense to transpile. even if not using TS, one would use i.e. webpack to tree shake, use babel for ECMAScript stuff not available in Node (say do expressions), neatly bundle everything together.

@aidan-rypens
Copy link
Author

@AidanRRR it makes sense to transpile. even if not using TS, one would use i.e. webpack to tree shake, use babel for ECMAScript stuff not available in Node (say do expressions), neatly bundle everything together.

For production code yes, also for this devtool?

@kroko
Copy link

kroko commented Jan 21, 2021

For production code yes, also for this devtool?

Sure, you cannot avoid transpiling if you are using vanilla JS, but having some ECMA stage-x features that requires Babel for Node.js to be able to run the code, or even more if TS.
Personally in development phase

  • for main and preload side I switched to electromon, which is configured to consume compile products and reload on changes
  • main and preload compiled products are generated by webpack, auto recompiles on source changes (watch)
  • for renderer side I use webpack + wds + HMR + react-refresh (main (BrowserWindow) consumes http://... on dev and file:// on other tiers).

@feljx
Copy link

feljx commented Feb 27, 2021

Looking more into this, I'm not actually sure anymore why it wouldn't work when transpiled... I should have written some notes to myself about this. If it works fine for you, then great. I'll keep this open until I have time to look more into this and potentially remove that readme note.

So I just ran into an issue where it is a problem. Custom webpack config with typescript and all the usual crazy module interop stuff that comes with it. Broke with a type error.
The workaround involves adding a tiny wrapper script in vanilla JS and requiring the transpiled app/module from within the wrapper.
#19

@swinc
Copy link

swinc commented Jul 2, 2021

Looking more into this, I'm not actually sure anymore why it wouldn't work when transpiled... I should have written some notes to myself about this. If it works fine for you, then great. I'll keep this open until I have time to look more into this and potentially remove that readme note.

Spent some time and it doesn't work when webpack'd because of the chokidar dependency, which contains file-system binary that doesn't make sense to pull into a webpack'd module (and doesn't work out of the box). Basically chokidar only makes sense when run directly by node because it's meant to watch the file system.

It works fine as far as I can tell when "transpiled" by TypeScript, although then you have to fiddle with webpack and TypeScript build tooling separately, and this increases the complexity of your whole build environment if you were relying on webpack and a TypeScript plugin loader before.

I can't think of a better fix than @feljx if you want everything to build through webpack. The module needs to be run directly by node and not packed into a webpack module.

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

No branches or pull requests

5 participants