svelte-loader-hot
svelte-loader-hot copied to clipboard
Support Webpack 5, drop copypasted webpack-virtual-modules
It drops webpack-virtual-modules in favor of much more simple and sane setup described here: https://github.com/webpack/webpack/issues/11074#issuecomment-648658214
The setup works both for webpack 4 and 5. Emitted css reloads just fine on component change on both of them.
This PR changes make use of custom loader string, virtualModules Map which contain pairs *.svelte.{index}.css: content and index to prevent key overlaps when compiling concurrently for SSR and browser.
The loader saves css string to the virtualModules Map and appends an import with custom loader string, relaunching svelte-loader with cssPath parameter, which makes it output css basically from the void (without a file) and pass it further to the .css loaders chain.
Every time css is read from the virtualModules Map it gets deleted to prevent leaks.
I'm currently using this approach in svelte-loader-hot on production.