@@ -19,6 +19,7 @@ import yaml from 'js-yaml';
19
19
20
20
import * as path from 'node:path' ;
21
21
import * as sass from 'sass' ;
22
+ import { eleventyImageTransformPlugin } from '@11ty/eleventy-img' ;
22
23
23
24
// noinspection JSUnusedGlobalSymbols
24
25
/**
@@ -92,7 +93,9 @@ export default function (eleventyConfig) {
92
93
eleventyConfig . addPassthroughCopy ( 'src/content/assets/dash' ) ;
93
94
eleventyConfig . addPassthroughCopy ( 'src/content/assets/js' ) ;
94
95
eleventyConfig . addPassthroughCopy ( { 'site-shared/packages/inject_dartpad/lib/inject_dartpad.js' : 'assets/js/inject_dartpad.js' } ) ;
95
- eleventyConfig . addPassthroughCopy ( 'src/content/assets/img' , { expand : true } ) ;
96
+ eleventyConfig . addPassthroughCopy ( 'src/content/assets/img/404-bg-pattern.jpg' ) ;
97
+ eleventyConfig . addPassthroughCopy ( 'src/content/assets/img/logo' ) ;
98
+ eleventyConfig . addPassthroughCopy ( 'src/content/assets/img/social' ) ;
96
99
eleventyConfig . addPassthroughCopy ( 'src/content/f' , {
97
100
expand : true ,
98
101
filter : / ^ (? ! _ ) .+ / ,
@@ -118,6 +121,37 @@ export default function (eleventyConfig) {
118
121
119
122
return content ;
120
123
} ) ;
124
+
125
+ // Optimize all images, generate an avif, webp, and png version,
126
+ // and indicate they should be lazily loaded.
127
+ // Save in `_site/assets/img` and update links to there.
128
+ eleventyConfig . addPlugin ( eleventyImageTransformPlugin , {
129
+ extensions : 'html' ,
130
+ formats : [ 'avif' , 'webp' , 'png' , 'svg' ] ,
131
+ svgShortCircuit : true ,
132
+ widths : [ 'auto' ] ,
133
+ defaultAttributes : {
134
+ loading : 'lazy' ,
135
+ decoding : 'async' ,
136
+ } ,
137
+ urlPath : '/assets/img/' ,
138
+ outputDir : '_site/assets/img/' ,
139
+ } ) ;
140
+ } else {
141
+ // To be more consistent with the production build,
142
+ // don't optimize images but still indicate they should be lazily loaded.
143
+ // Then save in `_site/assets/img` and update links to there.
144
+ eleventyConfig . addPlugin ( eleventyImageTransformPlugin , {
145
+ extensions : 'html' ,
146
+ formats : [ 'auto' ] ,
147
+ widths : [ 'auto' ] ,
148
+ defaultAttributes : {
149
+ loading : 'lazy' ,
150
+ decoding : 'async' ,
151
+ } ,
152
+ urlPath : '/assets/img/' ,
153
+ outputDir : '_site/assets/img/' ,
154
+ } ) ;
121
155
}
122
156
123
157
eleventyConfig . setQuietMode ( true ) ;
0 commit comments