-
-
Notifications
You must be signed in to change notification settings - Fork 114
hmr does not work for dependencies returned from svelte-preprocess #25
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
Comments
here's how vite's own css plugin does it: https://github.com/vitejs/vite/blob/2a89c57d3fb2dedbe595c4d49c454f3d138e6414/packages/vite/src/node/plugins/css.ts#L179 |
Here's my take on updating the module graph https://github.com/sveltejs/vite-plugin-svelte/tree/watch-preprocess-deps Unfortunately vites own importAnalysis plugin runs last and if i understand correctly whats happening it undoes my changes. :/ cc @rixo |
thank you for mentioning the windicss case here. @kaisermann whats the take on config files that change preprocessor output, should they be added to preprocess dependencies output? Would this apply to postcss.config.js too? |
@dominikg I'm not sure there's a bulletproof way to do this. We could do it for postcss.config.js and tsconfig.json, which are config files we need directly. However, a postcss plugin or a babel plugin, or anything really can request some file that we're not aware of. We could have a config to manually define some files as dependencies though. |
In an ideal world we would track all the config files that could affect preprocessor output, and recompile svelte components that were affected by one of the preprocessors and only trigger an update if the actual compiled output changed as a result of the config change. I guess there is a price to pay if you edit global config files and that price is a full reload. |
Yes, that's why I took the https://github.com/antfu/vite-plugin-restart into my setup. It got some globbing issues on Windows, which I am ironing out currently, but it does the job. Thankfully Vite is so quick that this full reload is barely noticable. I understand it is not ideal, but I'll take a slower correct response anytime over no response. Taking into account that config files rarely change, I suppose we can live with such workflow. |
Tracking config files isn't worth it. There's so many possible cases -- all of them soon expanding to .mjs, .cjs, etc -- that would be a promise we cannot fully deliver, scoring at best something between deceive and disappoint, depending on user setup. Furthermore, it's something nobody really expects, in a cold path with no high returns even if it worked... And, all in all, far more easier to handle in userland with restart plugin + I know what config files I'm actually using in my project (even that seems too much trouble to me). The initial point of the issue, tracking code dependencies, in the hot path, is what really matters IMO. |
As vites importAnalysis plugin prevents us from manipulating the module graph to add the dependencies here's an alternative approach: https://github.com/sveltejs/vite-plugin-svelte/tree/fix/watch-preprocessor-dependencies preprocess dependencies are watched for changes and when they are changed, it triggers a change event on the parent svelte component file so standard vite handleHotUpdate mechanism runs.
Tracking of dependencies/dependants is done via the compile cache Initial tests look good: https://github.com/sveltejs/vite-plugin-svelte/blob/fix/watch-preprocessor-dependencies/packages/playground/svelte-preprocess/__tests__/svelte-preprocess.spec.ts Thoughts? |
How do I test this? |
Either wait until its released (hopefully soon, just tryin to tie up a few loose ends when files get deleted/added) or clone and build yourself locally. Find me on discord if you need help with it. |
Thanks, no hurry. I'll wait for release. |
can confirm, with this branch it works like a charm! |
Description
During svelte-preprocess, additional dependencies can be encountered and are returned as an array. Changes to these files currently do not trigger the expected hot module reload during
vite dev
Reproduction
use one of the many ways to define an additional dependency by referencing a file in a svelte component that is then preprocessed. eg
Additional Information
original bugreport on sveltekit: sveltejs/kit#849
Things to do
The text was updated successfully, but these errors were encountered: