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

Live reloading changes from a common directory when using tsconfig paths #26

Open
lewisandrew opened this issue Jul 18, 2021 · 7 comments

Comments

@lewisandrew
Copy link

lewisandrew commented Jul 18, 2021

Just stumbled across this and I love the setup, thanks! I've used the create-app for react/ts/vite. I've added a src/common folder for shared code between main and renderer, but I've found that making changes to code in src/common doesn't trigger a reload of the main process.

I took a look through esbuilder package and I believe it may be these lines here that are only using src property from the config to determine a directory to watch. If I've understood correctly, I think we'd need another property to specify one or more "common" directories to additionally watch for.

@Kiyozz
Copy link
Owner

Kiyozz commented Jul 18, 2021

Hey,
Thanks you for your comment!

I use electron-esbuild myself for a personal project (papyrus-compiler-app in my profile).
I have a common folder too. But I do not have this problem. Have you any repo with the same problem?

@lewisandrew
Copy link
Author

Here's what I've got: https://github.com/lewisandrew/Vite-Electron-Test

@Kiyozz
Copy link
Owner

Kiyozz commented Jul 18, 2021

In which side the live reload does not refresh? In renderer?

If yes, this could be the vite server configuration that do not listen to common

@lewisandrew
Copy link
Author

It's working with renderer. It doesn't work with the main process. Starting dev you'll see the console log "hello main stuff..." that comes from the common function executed in main.ts. Editing the console log message and saving the file doesn't trigger a reload of the main process (the updated console log message doesn't get logged), but saving in the main.ts file does.

@Kiyozz
Copy link
Owner

Kiyozz commented Jul 19, 2021

I think I found the problem. I tested with common/logger.

In your main.ts, if you change import logger from '@/common/logger.js' by import logger from '../common/logger.js' (note the tsconfig paths removed).

esbuild does not seem to know that the file as changed cause of the tsconfig paths. Maybe esbuild needs a plugin?

I think this is not related to electron-esbuild.

@lewisandrew
Copy link
Author

Thanks for looking into this. I also see it working if I use relative paths. I tried fooling around with an esbuild plugin that onResolve sets the new path correctly, however unfortunately that didn't work. It seems that whatever is causing it to work with relative paths is being determined separately (or maybe before) from how esbuild resolves it.
https://github.com/lewisandrew/Vite-Electron-Test/commit/a7807331b3613ceefbacf7a0c55b1cb56b01f154

Any ideas on what other configuration I may need to change?

@Kiyozz
Copy link
Owner

Kiyozz commented Jul 21, 2021

The problem comes from the tool that looks for your sources dependencies (local files and node_modules).

It does not resolve paths aliases. I'm working on it. I'll maybe add a watchDirectories config options per environment (only if it can't be done via a tool that looks for dependencies)

@Kiyozz Kiyozz changed the title Live reloading changes from a common directory Live reloading changes from a common directory when using tsconfig paths Sep 23, 2021
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

2 participants