@@ -3,10 +3,10 @@ import path from 'path';
33import loaderUtils from 'loader-utils' ;
44import validateOptions from 'schema-utils' ;
55import { getImgproxyUrlBuilder } from './imgproxyUrlBuilder' ;
6- import { Breakpoint , OrderedBreakpointSource , SrcSet } from '../types' ;
6+ import { Breakpoint , OrderedBreakpointSource , SrcSet , Dpr } from '../types' ;
77import { imageUrls } from './plugin' ;
88import { schema } from './loaderOptionsSchema' ;
9- import { getBreakpointMedia } from '../utils' ;
9+ import { getBreakpointMedia , getPixelRations } from '../utils' ;
1010
1111// Такое имя используется, если нужна одна картинка для всех разрешений
1212// В таком случаем не будут сгенерированы медиа выражения для разных breakpoint'ов
@@ -19,7 +19,7 @@ export type LoaderOptions = {
1919 imagesHost : string ;
2020 host : string ;
2121 } ;
22- shouldResize : boolean ;
22+ originalPixelRatio : Dpr ;
2323} ;
2424
2525// Каждый импорт картинки проходит через этот лоадер и на выходе
@@ -30,12 +30,8 @@ export const loader = function (this: webpack.loader.LoaderContext, source: stri
3030
3131 validateOptions ( schema , options , { name : 'Imgproxy responsive loader' , baseDataPath : 'options' } ) ;
3232
33- // TODO
34- // Подготовить здесь массив с pixelRatios [1x 2x 3x] [1x 2x] [1x]
35- // Я не уверен в каком порядке должны быть элементы массива
36-
33+ const pixelRations : Dpr [ ] = getPixelRations ( options . originalPixelRatio )
3734 const breakpoints : Breakpoint [ ] = options . breakpoints ;
38-
3935 // Такой результат приходит от file-loader 'module.exports = "/build/myImage/mobile.all-4b767a7b.png";'
4036 // Получаем оригинальное имя файла изображения (originalImageFileName = mobile.all.png)
4137 const originalImageFileName = path . relative ( this . context , this . resourcePath ) ;
@@ -90,18 +86,9 @@ export const loader = function (this: webpack.loader.LoaderContext, source: stri
9086 } ;
9187 } else {
9288 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- }
89+ webpSrcSet = buildUrlsForPixelRatios ( pixelRations , outputImagePath , 'webp' ) ;
90+ originalExtensionSrcSet = buildUrlsForPixelRatios ( pixelRations , outputImagePath , originalExtension ) ;
91+
10592 data = {
10693 order,
10794 breakpointMedia,
0 commit comments