Skip plugin entirely in production builds - #5
Conversation
The plugin was consuming 90% of build time during `vite build` because Rolldown called into the transform hook for every module, even though it returned null immediately. Using Vite's `apply: "serve"` option removes the plugin entirely from the build pipeline in production, eliminating all hook call overhead. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
|
Warning Rate limit exceeded
⌛ How to resolve this issue?After the wait time has elapsed, a review can be triggered using the We recommend that you space out your commits to avoid hitting the rate limit. 🚦 How do rate limits work?CodeRabbit enforces hourly rate limits for each developer per organization. Our paid plans have higher rate limits than the trial, open-source and free plans. In all cases, we re-allow further reviews after a brief timeout. Please see our FAQ for further information. 📒 Files selected for processing (1)
📝 WalkthroughWalkthroughThe plugin now explicitly restricts execution to development mode by adding Changes
Estimated code review effort🎯 2 (Simple) | ⏱️ ~8 minutes Poem
🚥 Pre-merge checks | ✅ 3✅ Passed checks (3 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing Touches🧪 Generate unit tests (beta)
Comment |
There was a problem hiding this comment.
🧹 Nitpick comments (3)
tests/vite-plugin.test.ts (3)
76-80: Duplicateapplyassertion — consolidate into theplugin metadatadescribe block.This test (and its twin at line 252) only asserts
plugin.apply === "serve"— it's testing plugin metadata, nottransformortransformIndexHtmlbehaviour. Having the same one-liner assertion in two different describe blocks adds noise without coverage benefit.♻️ Suggested consolidation
Remove lines 76–80 and 252–256, and add a single test to the
plugin metadatadescribe block:describe("plugin metadata", () => { test("has correct name", () => { const plugin = solidGrab(); expect(plugin.name).toBe("solid-grab"); }); test("enforces pre", () => { const plugin = solidGrab(); expect(plugin.enforce).toBe("pre"); }); + + test("applies only during serve (skipped in production builds)", () => { + const plugin = solidGrab(); + expect(plugin.apply).toBe("serve"); + }); });🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed. In `@tests/vite-plugin.test.ts` around lines 76 - 80, Remove the duplicate one-line tests that only assert plugin.apply === "serve" (the test named "skips in production mode (apply: serve)" and its twin) and instead add a single assertion inside the existing "plugin metadata" describe block that checks the plugin metadata once; locate the creation of the plugin via solidGrab() and place expect(plugin.apply).toBe("serve") in that metadata block so metadata checks are consolidated and the redundant tests are deleted.
6-21:modeparameter increatePluginis now vestigial.
configResolvedonly readsconfig.rootafter theisDevremoval. Thecommandandmodefields injected intofakeConfigare passed to the hook but never consumed, making themodeparameter a no-op that could mislead future contributors into thinking production-mode behaviour can still be exercised through this helper.♻️ Suggested simplification
function createPlugin( options: Parameters<typeof solidGrab>[0] = {}, - mode: "development" | "production" = "development" ): Plugin { const plugin = solidGrab(options); - const fakeConfig = { - root: "/project", - command: mode === "development" ? "serve" : "build", - mode, - } as ResolvedConfig; + const fakeConfig = { root: "/project" } as ResolvedConfig; (plugin as any).configResolved(fakeConfig); return plugin; }🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed. In `@tests/vite-plugin.test.ts` around lines 6 - 21, The createPlugin helper has a vestigial mode parameter and populates fakeConfig.command and fakeConfig.mode which configResolved no longer consumes; remove the mode parameter from createPlugin, simplify fakeConfig to only include root (e.g., { root: "/project" } as ResolvedConfig), and update any test callers of createPlugin to the new signature so they no longer pass or rely on the removed mode argument; keep the call to (plugin as any).configResolved(fakeConfig) and the function name createPlugin unchanged.
240-250: Test name "in dev mode" is a slight misnomer after theisDevremoval.The hook no longer has an internal dev-mode guard; it runs whenever Vite invokes it (which is only during serve, thanks to
apply: "serve"). The name implies conditional dev-mode behaviour that no longer exists in the hook body.- test("returns tag descriptors in dev mode", () => { + test("returns tag descriptors when autoImport is enabled", () => {🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed. In `@tests/vite-plugin.test.ts` around lines 240 - 250, Rename the test to remove the "in dev mode" wording since isDev was removed: update the test description string in tests/vite-plugin.test.ts (the test that calls createPlugin() and invokes (plugin as any).transformIndexHtml()) to something like "returns tag descriptors" or "returns tag descriptors when invoked", keeping the rest of the test body unchanged so the assertion targets (createPlugin, transformIndexHtml, and the tag/attrs/injectTo expectations) remain the same.
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.
Nitpick comments:
In `@tests/vite-plugin.test.ts`:
- Around line 76-80: Remove the duplicate one-line tests that only assert
plugin.apply === "serve" (the test named "skips in production mode (apply:
serve)" and its twin) and instead add a single assertion inside the existing
"plugin metadata" describe block that checks the plugin metadata once; locate
the creation of the plugin via solidGrab() and place
expect(plugin.apply).toBe("serve") in that metadata block so metadata checks are
consolidated and the redundant tests are deleted.
- Around line 6-21: The createPlugin helper has a vestigial mode parameter and
populates fakeConfig.command and fakeConfig.mode which configResolved no longer
consumes; remove the mode parameter from createPlugin, simplify fakeConfig to
only include root (e.g., { root: "/project" } as ResolvedConfig), and update any
test callers of createPlugin to the new signature so they no longer pass or rely
on the removed mode argument; keep the call to (plugin as
any).configResolved(fakeConfig) and the function name createPlugin unchanged.
- Around line 240-250: Rename the test to remove the "in dev mode" wording since
isDev was removed: update the test description string in
tests/vite-plugin.test.ts (the test that calls createPlugin() and invokes
(plugin as any).transformIndexHtml()) to something like "returns tag
descriptors" or "returns tag descriptors when invoked", keeping the rest of the
test body unchanged so the assertion targets (createPlugin, transformIndexHtml,
and the tag/attrs/injectTo expectations) remain the same.
- Move apply: "serve" assertion into plugin metadata describe block - Remove duplicate one-line apply tests from transform/transformIndexHtml - Remove vestigial mode parameter from createPlugin helper - Rename "returns tag descriptors in dev mode" since isDev was removed Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
Summary
• Added
apply: "serve"to the Vite plugin config so the entire plugin is excluded from production builds• Removed the now-unnecessary
isDevguard from transform/transformIndexHtml hooks• Updated tests to verify the plugin metadata instead of testing dead code paths
Problem
During
vite build, Rolldown was calling into solid-grab'stransformhook for all 2541 modules. Even though it returnednullimmediately for production mode, the cumulative overhead of these calls made the plugin consume 90% of build time:Fix
Vite's
apply: "serve"option tells Vite to completely skip the plugin duringvite build. No hooks are called at all — the plugin simply doesn't exist in the build pipeline.Test plan
vite buildno longer shows solid-grab in PLUGIN_TIMINGS🤖 Generated with Claude Code
Summary by CodeRabbit
Release Notes
Refactor
Tests