vite-plugin-svelte
vite-plugin-svelte copied to clipboard
separate es modules for `<script context="module">` and `<script>` during dev / hmr
Describe the problem
Current implementation in svelte-hmr self-accepts updates to Component.svelte, which can cause broken references for exports of context=module
scripts. see #134
Describe the proposed solution
Instead of returning 1 es-module for Component.svelte js, return a facade wrapping 2 virtual modules, allowing for separate hmr updates and properly propagating updates of context=module
Alternatives considered
Use acceptNamedExports: false
option of svelte-hmr, letting updates bubble and live with extra reloads
Importance
would make my life easier
This is a draft to collect information and lay out a plan what has to be done and document experiments around it. If you have ideas or opinions on this topic, please share.
Note: This is also discussed in a discord thread.
since the addition of partial accept to vite and svelte-hmr 0.15 + vite-plugin-svelte 1.0.6 supporting it, the change described here would add little to no additional benefit and would add significant complexity.
We might revisit it later if other needs present themselves but for now the current solution does allow for granular updates even with context=module.