Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Building for production by default copies all files and folders from public (frustrating first time user experience) #10650

Closed
7 tasks done
garygreen opened this issue Oct 26, 2022 · 4 comments

Comments

@garygreen
Copy link

garygreen commented Oct 26, 2022

Describe the bug

I am a first time user of Vite, trying to give it a go. An issue I've ran into straight away is building for production library mode seems to copy all files and folders from public, even though the entry point is a super simple basic js file that doesn't import any of the files it's copied.

If you take a look at the reproduction url take a look at the dist folder that vite has built - it included these files and folder:

image

For our project those folders that it's copying is absolutely huge (gigabytes) and it actually looks like it's frozen the build process whilst it's copying all those files. Those public files aren't even used at all or referenced anywhere in the js - they just happen to sit in public because they should be publicly accessible, but have nothing to do with our build tools or bundle.

This is quite a frustrating experience as first timer coming to Vite. I've never experienced a bundler copy such a mass amount of files that weren't even referenced in the bundle.

Is this a bug? Or if it's working as intended, is it a sensible default? Is there somewhere in the docs I'm missing?

Reproduction

https://stackblitz.com/edit/vitejs-vite-bf6npy?file=main.js,public%2Fvite.svg&terminal=dev

Steps to reproduce

No response

System Info

System:
    OS: Windows 10 10.0.19043
    CPU: (4) x64 Intel(R) Core(TM) i5-2500K CPU @ 3.30GHz    
    Memory: 8.97 GB / 15.98 GB
  Binaries:
    Node: 16.13.2 - C:\Program Files\nodejs\node.EXE
    Yarn: 1.9.4 - C:\Program Files (x86)\Yarn\bin\yarn.CMD   
    npm: 5.10.0 - E:\Sites\cc-new\node_modules\.bin\npm.CMD  
  Browsers:
    Edge: Spartan (44.19041.1266.0), Chromium (106.0.1370.52)

Used Package Manager

npm

Logs

No response

Validations

@randName
Copy link

It is documented here: https://vitejs.dev/guide/assets.html#the-public-directory

Though I agree you do have a slight point about it not being the default behavior if unconfigured.

@zettadam
Copy link

zettadam commented Oct 27, 2022

This is a problem if you are building a library and you put any files not related to production output inside /public directory. Let's say you have example image files you use as props (URL or path to those images) when developing React components in Storybook (with vite builder which started using a single vite.config). I think these files should not be part of a NPM package unless specifically selected (or configured).

@randName
Copy link

I see that #10550 was recently added too.

I just thought of a suggestion, which is getting the total size of publicDir before copying (also a recursive action) and emitting a warning if the total size or total number of files crosses a certain threshold. the check can be skipped if options have been explicitly set.

@bluwy
Copy link
Member

bluwy commented Nov 9, 2023

Closing this as #10550 should fix this.

@bluwy bluwy closed this as completed Nov 9, 2023
@github-actions github-actions bot locked and limited conversation to collaborators Nov 24, 2023
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

No branches or pull requests

5 participants