Skip to content

feat(loader): add the disk cache option - #17

Merged
dangreen merged 1 commit into
mainfrom
add-loader-cache
Aug 19, 2026
Merged

feat(loader): add the disk cache option#17
dangreen merged 1 commit into
mainfrom
add-loader-cache

Conversation

@dangreen

Copy link
Copy Markdown
Member

Adds a cache boolean to @srcset/loader, mirroring the option of @srcset/vite-plugin but 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: true gives the loader its own storage under node_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.

  • SrcSetLoaderOptions takes cache?: boolean and drops the inherited SrcSetCacheStorage field, the same shape SrcSetVitePluginOptions uses
  • getSharedCache(context) memoizes one storage per compiler context, mirroring getSharedLimit
  • Only the module options reach generateSrcSetModule now - the loader-specific ones (name, emitFile, publicPath, …) no longer leak into it
  • Covered on both webpack and rspack: with the option a second build does not run the optimizer again and still emits the assets; without it the optimizer runs twice

🤖 Generated with Claude Code

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.
@dangreen
dangreen merged commit 7675bbc into main Aug 19, 2026
7 checks passed
@dangreen
dangreen deleted the add-loader-cache branch August 19, 2026 20:07
@github-actions github-actions Bot mentioned this pull request Aug 19, 2026
@coveralls

Copy link
Copy Markdown

Coverage Report for CI Build 32296723641

Coverage decreased (-0.3%) to 91.37%

Details

  • Coverage decreased (-0.3%) from the base build.
  • Patch coverage: 2 uncovered changes across 1 file (5 of 7 lines covered, 71.43%).
  • 1 coverage regression across 1 file.

Uncovered Changes

File Changed Covered %
packages/loader/src/cache.ts 6 4 66.67%
Total (2 files) 7 5 71.43%

Coverage Regressions

1 previously-covered line in 1 file lost coverage.

File Lines Losing Coverage Coverage
packages/loader/src/template.ts 1 95.83%

Coverage Stats

Coverage Status
Relevant Lines: 749
Covered Lines: 700
Line Coverage: 93.46%
Relevant Branches: 572
Covered Branches: 507
Branch Coverage: 88.64%
Branches in Coverage %: Yes
Coverage Strength: 94291.23 hits per line

💛 - Coveralls

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

Successfully merging this pull request may close these issues.

2 participants