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

build.emptyOutDir no longer empties out the entire directory since v3.2.x #10696

Open
7 tasks done
benjaminprojas opened this issue Oct 28, 2022 · 5 comments
Open
7 tasks done

Comments

@benjaminprojas
Copy link

Describe the bug

In the past, using build.emptyOutDir would empty out the entire directory defined by build.outDir even when the build.rollupOptions.output.dir was set to a different directory. Since v3.2.0 this has changed to only empty out what is defined in build.rollupOptions.output.dir

Reproduction

https://stackblitz.com/edit/vitejs-vite-lmgy3k?file=vite.config.js,package.json

Steps to reproduce

There is a file inside dist called: file-to-be-removed.html. This file should be deleted when a new build is made (dist directory is emptied).

run npm run build to see that the files inside the dist directory are not deleted, only the files inside the dist/assets directory are deleted.

Alternatively, use the following for 3.1.8 to see it working as expected: https://stackblitz.com/edit/vitejs-vite-lmgy3k?file=vite.config.js,package.json

System Info

System:
    OS: macOS 12.6
    CPU: (10) arm64 Apple M1 Max
    Memory: 137.77 MB / 32.00 GB
    Shell: 5.8.1 - /bin/zsh
  Binaries:
    Node: 16.15.0 - /usr/local/bin/node
    npm: 8.9.0 - /opt/homebrew/bin/npm
  Browsers:
    Chrome: 106.0.5249.119
    Firefox: 104.0
    Safari: 16.0
  npmPackages:
    @vitejs/plugin-react: ^1.3.2 => 1.3.2 
    vite: 3.2.1 => 3.2.1

Used Package Manager

npm

Logs

No response

Validations

@sapphi-red
Copy link
Member

The previous behavior was considered as a bug and changed by #9748. I'm not sure which one is more natural.

@patak-dev
Copy link
Member

What we defined in #9748 for nested output dirs is that the contents of all output folders would be deleted (but not the nested folder structure). cc @qmhc

The repro doesn't have multiple output dirs, only one that overwrites the value of build.outDir. This is a strange setup, I don't know if we should count this as a regression. Shouldn't assetFileNames be used here?
But if users are configuring Vite in this way, maybe it isn't a bad idea to always include build.outDir as target to remove its content (that should fix this issue)

@qmhc
Copy link
Contributor

qmhc commented Oct 31, 2022

In my thought, we can allow the build.outDir is optional with descripting that any build.rollupOptions.output.dir will overwrite it, and we can warn when users using both them.

@benjaminprojas
Copy link
Author

@patak-dev the repro was minimal to show how to reproduce, but we do use assetFileNames as well. We have a pretty complex setup where we put things in different folders inside the dist directory. However I want the entire outDir to be emptied during each build.

Also, stands to reason (imho) that if you have:

outDir      : 'dist',
emptyOutDir : true

Then the dist directory should be emptied.

@arnaudbroes
Copy link

I completely agree with @benjaminprojas here. I think that the root dist directory should be the one that is emptied out.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

5 participants