Get size of build to display on page #3158
-
I am trying to get the total size of the build folder to display it on the stats-page of my project. I tried to do this using eleventyConfig.addTransform("addFileSize", async (content, outputPath) => {
if (outputPath.endsWith(".html") && content.includes('FILESIZE')) {
const fileSize = Buffer.from(content).length;
return content.replace('FILESIZE', Math.round((fileSize / 1024) * 100) / 100);
}
return content;
}); I am displaying it by replacing a string called FILESIZE on a website, thats how I got it to work. Now I want to show the entire size but since addTransform only works on each file and cannot see the others this approach doesn't work. Any ideas how I can get this done? |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment 2 replies
-
I haven't tried it, but there is https://www.11ty.dev/docs/events/#event-arguments eleventyConfig.on('eleventy.after', async ({ dir, results, runMode, outputMode }) => {
// Read more below
}); So maybe after a build completes, you could find the total file size of the |
Beta Was this translation helpful? Give feedback.
I figured out it,
eleventy.after
only provides the result of what has been written to disk which is why replacing the word only changed it there. With following function it overwrites the file with the replaced placeholder: