11const filters = require ( "./utils/filters.js" )
22const esbuild = require ( "esbuild" ) ;
33const { sassPlugin } = require ( "esbuild-sass-plugin" ) ;
4+ const htmlmin = require ( "html-minifier" ) ;
45
56module . exports = function ( eleventyConfig ) {
67
78 eleventyConfig . addGlobalData ( "generated" , ( ) => {
89 let now = new Date ( ) ;
910 return new Intl . DateTimeFormat (
10- "en-GB" , { dateStyle : "medium" , timeStyle : "long" , timeZone : "UTC" }
11+ "en-GB" , { dateStyle : "medium" , timeStyle : "long" , timeZone : "UTC" }
1112 ) . format ( now ) ;
1213 } ) ;
1314
@@ -16,17 +17,29 @@ module.exports = function (eleventyConfig) {
1617 eleventyConfig . addFilter ( filterName , filters [ filterName ] )
1718 } )
1819
20+ eleventyConfig . addTransform ( "htmlmin" , ( content , outputPath ) => {
21+ if ( outputPath && outputPath . endsWith ( ".html" ) && process . env . NODE_ENV === "production" ) {
22+ return htmlmin . minify ( content , {
23+ useShortDoctype : true ,
24+ removeComments : true ,
25+ collapseWhitespace : true
26+ } ) ;
27+ }
28+ return content ;
29+ } ) ;
30+
1931 eleventyConfig . on ( "afterBuild" , ( ) => {
2032 return esbuild . build ( {
2133 entryPoints : [ "_site/_esbuild/app.scss" , "_site/_esbuild/app.js" ] ,
2234 outdir : "_site/assets" ,
2335 bundle : true ,
36+ legalComments : "linked" ,
2437 minify : process . env . NODE_ENV === "production" ,
2538 sourcemap : process . env . NODE_ENV !== "production" ,
2639 plugins : [ sassPlugin ( ) ]
2740 } ) ;
2841 } ) ;
29-
42+
3043 eleventyConfig . addWatchTarget ( "./src/sass/" ) ;
3144 eleventyConfig . addWatchTarget ( "./src/js/" ) ;
3245
0 commit comments