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 with custom JS #62

Closed
mattvr opened this issue May 15, 2024 · 3 comments
Closed

Live reloading with custom JS #62

mattvr opened this issue May 15, 2024 · 3 comments

Comments

@mattvr
Copy link
Contributor

mattvr commented May 15, 2024

I have a custom JS script I'm separately building and including in my extension (outside of webpack).

If I include it in ./scripts/, I get a $RefreshSig$ is not defined error as I believe the webpack processing on top is causing a conflict.

If I include it in ./public/, everything works great, but live reloading doesn't work and I have to restart the browser fully every time my script changes.

Ideally, I'd like for my custom JS (and other assets like images) to refresh without restarting the browser or throwing the webpack error.

No worries if out of scope, just figured I'd ask if there's an existing option or a bug I'm hitting – I could feasibly work around this.

Thank you for the awesome tool!

@cezaraugusto
Copy link
Owner

Hi there! Thanks!

If you are trying to load a source (not bundled) file in scripts/ and you get a $RefreshSig$ is not defined, that's a bug.

However if this file is bundled somewhere else outside Extension.js (like you said -- separately building and including in your extension), then scripts/ will fail if there are variables and imports outside the scope, as it has no access to the external bundling system. In this case, adding them to public/ might be the right choice. However, since it was designed for static assets, it does not listen for file changes.

I think having public/ to listen to file changes wouldn't affect existing functionality, but this is currently far from priorities. If you're feeling adventurous, editing the CopyPublicFolder file is the alternative for handling reload of public/ assets. I theorize that adding a listener to the change event in there would make your request possible. Something like:

watcher.on('change', (filePath: string) => {
  const target = path.join(output, path.relative(projectPath, filePath))
  this.copyFile(filePath, target)
})

The manual test would be adding a file to public/ and asserting that Extension.js reloads if they change. I added some instructions to run the project locally in CONTRIBUTING.md. If you want to give it a go, I can definitely review.

@mattvr
Copy link
Contributor Author

mattvr commented May 19, 2024

Great tip, that did it! @cezaraugusto I've tested and submitted a PR for here and updated docs, linked above.

@cezaraugusto
Copy link
Owner

Fixed by #64

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