Skip to content

fix(builder-vite): avoid duplicate publicDir copies with staticDirs#34524

Open
harshit-d3v wants to merge 1 commit intostorybookjs:nextfrom
harshit-d3v:fix/vite-publicdir-staticdirs
Open

fix(builder-vite): avoid duplicate publicDir copies with staticDirs#34524
harshit-d3v wants to merge 1 commit intostorybookjs:nextfrom
harshit-d3v:fix/vite-publicdir-staticdirs

Conversation

@harshit-d3v
Copy link
Copy Markdown

@harshit-d3v harshit-d3v commented Apr 11, 2026

Summary

  • disable Vite's build-time publicDir copy when Storybook staticDirs already includes the same directory
  • prevent duplicate root-level asset copies during static builds for Vite-based Storybook projects
  • avoid cases where files such as public/index.json can overwrite Storybook's generated storybook-static/index.json
  • add regression tests covering default and custom publicDir values, plus build vs development behavior

Closes #24627.

Testing

  • yarn vitest run code/builders/builder-vite/src/vite-config.test.ts

Summary by CodeRabbit

  • Tests

    • Added test coverage for Vite builder's public directory handling with static directories in build and development modes.
  • Bug Fixes

    • Improved Vite builder's public directory configuration based on static directory mappings during production builds.

@coderabbitai
Copy link
Copy Markdown
Contributor

coderabbitai bot commented Apr 11, 2026

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro

Run ID: 0034c793-ce8c-49cc-94b2-224a39da99fa

📥 Commits

Reviewing files that changed from the base of the PR and between aae6c95 and dd73cf4.

📒 Files selected for processing (2)
  • code/builders/builder-vite/src/vite-config.test.ts
  • code/builders/builder-vite/src/vite-config.ts

📝 Walkthrough

Walkthrough

These changes add logic to Storybook's Vite builder to conditionally disable Vite's publicDir during production builds when user-defined staticDirs already map to the same resolved directory. Tests verify this behavior across different build modes and configurations.

Changes

Cohort / File(s) Summary
Core Implementation
code/builders/builder-vite/src/vite-config.ts
Adds helper functions to resolve effective publicDir from Vite config and check if staticDirs mappings match it. Sets publicDir: false in build mode when static dir mapping aligns with resolved publicDir.
Test Additions
code/builders/builder-vite/src/vite-config.test.ts
Introduces test helpers (createOptions, createTempProject) and four test cases validating commonConfig behavior with publicDir disabled in build mode when staticDirs maps to the same directory, and enabled in other scenarios.

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~25 minutes


Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

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.

[Bug]: "../public" is always copied in the static build root even if I set it to go elsewhere

1 participant