Describe the bug
When running the generator, the content of _site is not compeltely rebuilt. In other words, files that ought to be removed persist after running Eleventy.
To Reproduce
npx eleventy --watch or npx eleventy). _site/img/ should now existExpected behavior
_site/img/ should NOT exist (but it does)
Environment:
If I am not mistaken, Eleventy does not clean the _site directory every time it runs. I generally create a clean task to do that using NPM script, Gulp, etc.
That appears to be the case. But is there a good reason for Eleventy to _not_ carry this out?
Some SSG will erase the output directory, others will not. Just a choice, both options have trade-offs.
I would say that 11ty should not delete everything due to the fact you might be creating other things inside the directory from other sources. Possibly... I'm just trying to thing as to why you wouldn't want a directory removed completely outside your control. You know more or less what's going on but 11ty couldn't be expected to know the same.
As for a flag that would allow this I reckon it could be a good option. Maybe there's already a enhancement request for this?
A quick clean NPM script will do the job, so I don't personally see the use for a flag.
Given the responses, the following appears to be a decent cross-platform and safe solution:
const del = require('del');
module.exports = function (eleventyConfig) {
const dirToClean = '_site/*';
del(dirToClean);
// rest of .eleventy.js config
};
However, it still seems quite odd that eliminating an addPassthroughCopy invocation will not result in the elimination of the associated subdirectory within the _site directory.
Thanks for the little piece of code. I might keep that handy for a project one day @jeffreysbrother
The think is I still wouldn't be comfortable with 11ty simple deleting directories to rebuild them. I'm just afraid of what could go missing by automating this if you are not aware of it.
@bikingbadger One thing to keep in mind is that many hosts like Netlify and Heroku will do a full rebuild each time they run - so all files get cleaned automatically.
With that said, I've got a clean step in gulp for when I'm working locally. It might be handy for Eleventy to have something built in for this.
mmmmm. OK then I guess this could be something to add. Would you think this should be done by default @edwardhorsford ?
Please, don't wipe the target directory on rebuilds.
I had that experienced with harp.js and had to restore my other services from a backup :-(
@Ryuno-Ki, I'm not very familiar with a scenario such as this, but I understand now why the target directory ought not be wiped in certain cases.
How about this alternative: Instead of wiping the _site directory completely, we at least ensure that an elimination of an addPassthroughCopy invocation deletes the corresponding directories that it passes to _site.
My thoughts would be that if this existed, it should be an all or nothing thing (wipe the target completely), and configurable (default off).
Duplicate of #19!
Most helpful comment
My thoughts would be that if this existed, it should be an all or nothing thing (wipe the target completely), and configurable (default off).