feat(loader): add the disk cache option - #17
Merged
Merged
Conversation
Off by default, unlike the vite plugin: the persistent cache of webpack and rspack already covers repeated builds when it is enabled. With `cache: true` the variants are stored in `node_modules/.cache/srcset`, so a rebuild skips the generation regardless of the bundler settings.
Draft
Coverage Report for CI Build 32296723641Coverage decreased (-0.3%) to 91.37%Details
Uncovered Changes
Coverage Regressions1 previously-covered line in 1 file lost coverage.
Coverage Stats
💛 - Coveralls |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Adds a
cacheboolean to@srcset/loader, mirroring the option of@srcset/vite-pluginbut off by default.The asymmetry is deliberate. The vite plugin has to cache: Vite has no persistent cache for plugin work, so without it every dev server start regenerates every variant. Webpack and rspack do have a persistent cache, so when it is enabled it already covers the loader - measured on the rspack example, 30 s of image generation on a cold start drops to 2 s on the next one, and the dev server comes up in 154 ms.
But that cache is off by default in both bundlers, and a project that does not enable it pays the full generation cost on every start.
cache: truegives the loader its own storage undernode_modules/.cache/srcset, independent of the bundler settings - on the same example, 30 s to 1 s. Keyed by the source contents and the generate options, so it also survives config edits that invalidate the bundler cache wholesale.SrcSetLoaderOptionstakescache?: booleanand drops the inheritedSrcSetCacheStoragefield, the same shapeSrcSetVitePluginOptionsusesgetSharedCache(context)memoizes one storage per compiler context, mirroringgetSharedLimitgenerateSrcSetModulenow - the loader-specific ones (name,emitFile,publicPath, …) no longer leak into it🤖 Generated with Claude Code