Repository navigation
[RFC] cleaning distDir on next build #6009
Replies: 35 comments 9 replies
|
Maybe only clean the HMR files? |
|
It's not just HMR files. It's static files in |
|
Do you know what's the rationale behind running If that's the case, I guess they (maybe unknowningly) suffer from the same problem, and need some sort of cleaning solution as well. (although it rather sounds like an antipattern to me) |
|
Probably a good idea to cc @DullReferenceException @alexindigo @ztanner |
|
@timneutkens Sounds like you're proposing to auto clean up distDir prior running |
|
|
|
could it be an idea to clean at the end of the build? i.e.
Edit: |
|
Sounds like too much complexity imo. |
Completely agree. Just mentioning it in case you'd favor a bit of complexity over adding another option, it's always a trade off 🙂. |
|
@timneutkens if it's just build then we're good :) |
|
Right exactly what I thought 💯 |
|
+1, this makes total sense and would not break things for us. |
|
Why not release with opt-in flag (let's say That way if you need to keep it you have a major version to add the |
|
We're already going to have a major version with current changes, hence why I created this rfc. |
it sounds good to me and that's exactly what I ended up doing for my blog |
|
Hi i seem to be experiencing this same issue. my question is would there be a problem if just add the .next folder to my git ignore because it really messing up my files when i want to add files and make commits.. i get a whole bunch of webpack stuff screaming in my face. |
|
@MuhammedAO Definitely do that. Build output files should not be in your repo. They get recreated anytime you build. Unless there's a specific reason to have such files checked into source control, this principle should apply to any project. |
|
What's the status of this RFC? |
|
I cannot upload static site to CDN due to huge files that are added to out folder if I do any local |
|
I'm having a similar issue, Next.JS hosted in AWS EC2, deployed with PM2, |
|
Hello guys, I'm stepping in with the same concern with next build && next export producing all the extra build files in NextJs 10. Is the plan to release an option for cleanup before new export command still up? Right now on Windows I do this using Gulp: package.json script: "export-prod": "gulp preBuildCleanDirs && next build && next export"gulpfile.js: const gulp = require("gulp");
const clean = require("gulp-clean");
function cleanNextDir() {
return gulp.src(".next/*", {read: false})
.pipe(clean({force: true}));
}
function cleanOutDir() {
return gulp.src("out/*", {read: false})
.pipe(clean({force: true}));
}
exports.preBuildCleanDirs = gulp.series(
cleanNextDir,
cleanOutDir,
); |
|
Run This will work: |
|
For my purposes it would have been nice to have the previous build available until the new one is finished, then I could restart the app server and then purge the old build from the server. I ultimately decided against maintaining my own build process and just moved to Vercel but an ever-growing build output directory is not ideal for those looking to self-host in general. |
|
Keeping old versions of builds might be useful when visitors are browsing your site between 2 builds ? Maybe the best of both world would be to keep the last I am pretty new to Next.js so I might be mistaken. |
|
As a new user to next.js, I got confused with the output of It turned out it's because I did a I'd need to duplicate the project I think to run a separate instance, or use something like Docker as a workaround. Alternatively, if My initial confusion was due to files like At the same time, the HTML output for the page has plenty of content referencing JS scripts, but in this case the page built is basic enough that no JS is needed for it. That's presumably out of scope for the exporter to know and could be handled by the developer through post-process tooling. |
|
Looks like this has shipped in Next.js 11: https://nextjs.org/docs/upgrading#cleaning-the-distdir-is-now-a-default 🎉 |
|
Sorry for bumping this old thread, but I am seeing the issue discussed here when running We use Contentful, which triggers a rebuild when content changes (via a web-hook). Unfortunately, when the old Anything I am missing here? EDIT: It seems my problem was the That is an issue though, because data fetches to CDNs like Contentful will then be stale even after re-building the whole site. |
|
Just stumbled on this as well... this has caused absolute havoc for us, I'm astonished that the build step doesn't automatically clear the cache. We lost weeks trying to figure out why old content was still loading. |
|
What am I missing here? Deleting the |

Uh oh!
There was an error while loading. Please reload this page.
Feature request
Is your feature request related to a problem? Please describe.
Currently Next.js will keep the
distDir(by default.next) when runningnext buildbecause some deployment strategies involve runningnext buildwhile the production application is running. However in most cases you actually want to start with a clean directory. For example when runningnext exportafter the build and Next.js having been in development mode before the build, this would cause HMR files to be written to the export out directory as outlined in #5554.Describe the solution you'd like
One solution is cleaning distDir by default and providing an option to opt-out of this behavior. I'd like to get some feedback on this though.
All reactions