[RFC] cleaning distDir on next build #6009
Replies: 33 comments 9 replies
-
Maybe only clean the HMR files? |
Beta Was this translation helpful? Give feedback.
-
It's not just HMR files. It's static files in |
Beta Was this translation helpful? Give feedback.
-
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) |
Beta Was this translation helpful? Give feedback.
-
Probably a good idea to cc @DullReferenceException @alexindigo @ztanner |
Beta Was this translation helpful? Give feedback.
-
@timneutkens Sounds like you're proposing to auto clean up distDir prior running |
Beta Was this translation helpful? Give feedback.
-
|
Beta Was this translation helpful? Give feedback.
-
could it be an idea to clean at the end of the build? i.e.
Edit: |
Beta Was this translation helpful? Give feedback.
-
Sounds like too much complexity imo. |
Beta Was this translation helpful? Give feedback.
-
Completely agree. Just mentioning it in case you'd favor a bit of complexity over adding another option, it's always a trade off 🙂. |
Beta Was this translation helpful? Give feedback.
-
@timneutkens if it's just build then we're good :) |
Beta Was this translation helpful? Give feedback.
-
Right exactly what I thought 💯 |
Beta Was this translation helpful? Give feedback.
-
+1, this makes total sense and would not break things for us. |
Beta Was this translation helpful? Give feedback.
-
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 |
Beta Was this translation helpful? Give feedback.
-
We're already going to have a major version with current changes, hence why I created this rfc. |
Beta Was this translation helpful? Give feedback.
-
it sounds good to me and that's exactly what I ended up doing for my blog |
Beta Was this translation helpful? Give feedback.
-
Are there any further progress about this RFC? I still find next keeping the old version of static files after |
Beta Was this translation helpful? Give feedback.
-
I'm not sure if this is from the same issue, but when developing locally, then running
I get a never-ending list of:
Adding Also for context, i'm developing locally, and running |
Beta Was this translation helpful? Give feedback.
-
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. |
Beta Was this translation helpful? Give feedback.
-
@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. |
Beta Was this translation helpful? Give feedback.
-
What's the status of this RFC? |
Beta Was this translation helpful? Give feedback.
-
I cannot upload static site to CDN due to huge files that are added to out folder if I do any local |
Beta Was this translation helpful? Give feedback.
-
@timneutkens any updates on this? |
Beta Was this translation helpful? Give feedback.
-
I'm having a similar issue, Next.JS hosted in AWS EC2, deployed with PM2, |
Beta Was this translation helpful? Give feedback.
-
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,
); |
Beta Was this translation helpful? Give feedback.
-
Run This will work:
|
Beta Was this translation helpful? Give feedback.
-
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. |
Beta Was this translation helpful? Give feedback.
-
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. |
Beta Was this translation helpful? Give feedback.
-
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. |
Beta Was this translation helpful? Give feedback.
-
Looks like this has shipped in Next.js 11: https://nextjs.org/docs/upgrading#cleaning-the-distdir-is-now-a-default 🎉 |
Beta Was this translation helpful? Give feedback.
-
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. |
Beta Was this translation helpful? Give feedback.
-
Feature request
Is your feature request related to a problem? Please describe.
Currently Next.js will keep the
distDir
(by default.next
) when runningnext build
because some deployment strategies involve runningnext build
while the production application is running. However in most cases you actually want to start with a clean directory. For example when runningnext export
after 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.
Beta Was this translation helpful? Give feedback.
All reactions