@@ -19,6 +19,7 @@ export type LoaderOptions = {
1919 imagesHost : string ;
2020 host : string ;
2121 } ;
22+ shouldResize : boolean ;
2223} ;
2324
2425// Каждый импорт картинки проходит через этот лоадер и на выходе
@@ -29,6 +30,10 @@ export const loader = function (this: webpack.loader.LoaderContext, source: stri
2930
3031 validateOptions ( schema , options , { name : 'Imgproxy responsive loader' , baseDataPath : 'options' } ) ;
3132
33+ // TODO
34+ // Подготовить здесь массив с pixelRatios [1x 2x 3x] [1x 2x] [1x]
35+ // Я не уверен в каком порядке должны быть элементы массива
36+
3237 const breakpoints : Breakpoint [ ] = options . breakpoints ;
3338
3439 // Такой результат приходит от file-loader 'module.exports = "/build/myImage/mobile.all-4b767a7b.png";'
@@ -66,6 +71,8 @@ export const loader = function (this: webpack.loader.LoaderContext, source: stri
6671 let webpSrcSet : SrcSet , originalExtensionSrcSet : SrcSet , data : OrderedBreakpointSource ;
6772 // Отключает процессинг картинок, генерируется srcSet только для оригинального типа изображения
6873 if ( options . imgproxy . disable ) {
74+ // TODO пока не смотрим disable
75+
6976 originalExtensionSrcSet = {
7077 '1x' : outputImagePath ,
7178 '2x' : outputImagePath ,
@@ -82,9 +89,19 @@ export const loader = function (this: webpack.loader.LoaderContext, source: stri
8289 ] ,
8390 } ;
8491 } else {
85- const buildUrlsForAllPixelRatios = getImgproxyUrlBuilder ( options . imgproxy ) ;
86- webpSrcSet = buildUrlsForAllPixelRatios ( outputImagePath , 'webp' ) ;
87- originalExtensionSrcSet = buildUrlsForAllPixelRatios ( outputImagePath , originalExtension ) ;
92+ const buildUrlsForPixelRatios = getImgproxyUrlBuilder ( options . imgproxy ) ;
93+ console . log ( options . shouldResize )
94+ if ( options . shouldResize ) {
95+ // TODO убрать хардкод, вынести в опции лоадера?
96+ // originalRatio: 3x -> 3x 2x 1x
97+ // originalRatio: 2x -> 2x 1x
98+ // originalRatio: 1x -> 1x
99+ webpSrcSet = buildUrlsForPixelRatios ( [ '1x' , '2x' , '3x' ] , outputImagePath , 'webp' ) ;
100+ originalExtensionSrcSet = buildUrlsForPixelRatios ( [ '1x' , '2x' , '3x' ] , outputImagePath , originalExtension ) ;
101+ } else {
102+ webpSrcSet = buildUrlsForPixelRatios ( [ '1x' ] , outputImagePath , 'webp' ) ;
103+ originalExtensionSrcSet = buildUrlsForPixelRatios ( [ '1x' ] , outputImagePath , originalExtension ) ;
104+ }
88105 data = {
89106 order,
90107 breakpointMedia,
@@ -100,7 +117,7 @@ export const loader = function (this: webpack.loader.LoaderContext, source: stri
100117 ] ,
101118 } ;
102119 // Добавляем ссылки на картинки через imgproxy в глобальный объект
103- imageUrls . push ( ...Object . values ( webpSrcSet ) , ...Object . values ( originalExtensionSrcSet ) ) ;
120+ imageUrls . push ( ...( Object . values ( webpSrcSet ) as string [ ] ) , ...( Object . values ( originalExtensionSrcSet ) as string [ ] ) ) ;
104121 }
105122
106123 const result : OrderedBreakpointSource = data ;
0 commit comments