11const fs = require ( 'fs' ) ;
22const inclusiveLangPlugin = require ( '@11ty/eleventy-plugin-inclusive-language' ) ;
3+ const cacheBuster = require ( '@mightyplow/eleventy-plugin-cache-buster' ) ;
34const htmlmin = require ( 'html-minifier' ) ;
45const { minify } = require ( 'terser' ) ;
56const siteSettings = require ( './src/globals/site.json' ) ;
@@ -10,6 +11,22 @@ module.exports = function (eleventyConfig) {
1011
1112 eleventyConfig . addPlugin ( inclusiveLangPlugin ) ;
1213
14+ if ( process . env . ELEVENTY_ENV === 'production' ) {
15+ eleventyConfig . addPlugin ( cacheBuster ( { outputDirectory : 'dist' } ) ) ;
16+
17+ eleventyConfig . addTransform ( 'htmlmin' , function ( content , outputPath ) {
18+ if ( outputPath && outputPath . endsWith ( '.html' ) ) {
19+ return htmlmin . minify ( content , {
20+ useShortDoctype : true ,
21+ removeComments : true ,
22+ collapseWhitespace : true ,
23+ } ) ;
24+ }
25+
26+ return content ;
27+ } ) ;
28+ }
29+
1330 eleventyConfig . addNunjucksAsyncFilter ( 'jsmin' , async function (
1431 code ,
1532 callback
@@ -43,22 +60,6 @@ module.exports = function (eleventyConfig) {
4360 } ,
4461 } ) ;
4562
46- eleventyConfig . addTransform ( 'htmlmin' , function ( content , outputPath ) {
47- if (
48- process . env . ELEVENTY_ENV === 'production' &&
49- outputPath &&
50- outputPath . endsWith ( '.html' )
51- ) {
52- return htmlmin . minify ( content , {
53- useShortDoctype : true ,
54- removeComments : true ,
55- collapseWhitespace : true ,
56- } ) ;
57- }
58-
59- return content ;
60- } ) ;
61-
6263 return {
6364 pathPrefix : siteSettings . baseUrl ,
6465 dir : {
0 commit comments