@@ -22,30 +22,37 @@ To use Images with **all** your app's images, define a global [loaderFile](https
2222
2323Add the following settings to the ** next.config.js** file located at the root our your Next.js application.
2424
25- ``` js
25+ ``` ts
2626module .exports = {
2727 images: {
2828 loader: ' custom' ,
29- loaderFile: ' ./imageLoader.js ' ,
29+ loaderFile: ' ./imageLoader.ts ' ,
3030 },
3131}
3232```
3333
34- Next, create the ` imageLoader.js ` file in the specified path (relative to the root of your Next.js application).
34+ Next, create the ` imageLoader.ts ` file in the specified path (relative to the root of your Next.js application).
3535
36- ``` js
37- const normalizeSrc = src => {
38- return src .startsWith (' / ' ) ? src .slice (1 ) : src;
36+ ``` ts
37+ const normalizeSrc = ( src : string ) => {
38+ return src .startsWith (" / " ) ? src .slice (1 ) : src ;
3939};
4040
41- export default function cloudflareLoader ({ src, width, quality }) {
42- const params = [` width=${ width} ` ];
43- if (quality) {
44- params .push (` quality=${ quality} ` );
45- }
46- const paramsString = params .join (' ,' );
47- return ` /cdn-cgi/image/${ paramsString} /${ normalizeSrc (src)} ` ;
48- };
41+ export default function cloudflareLoader({
42+ src ,
43+ width ,
44+ quality ,
45+ }: { src: string ; width: number ; quality? : number }) {
46+ if (process .env .NODE_ENV === " development" ) {
47+ return src ;
48+ }
49+ const params = [` width=${width } ` ];
50+ if (quality ) {
51+ params .push (` quality=${quality } ` );
52+ }
53+ const paramsString = params .join (" ," );
54+ return ` /cdn-cgi/image/${paramsString }/${normalizeSrc (src )} ` ;
55+ }
4956```
5057
5158### Custom Loaders
@@ -60,6 +67,9 @@ const normalizeSrc = src => {
6067};
6168
6269const cloudflareLoader = ({ src, width, quality }) => {
70+ if (process .env .NODE_ENV === " development" ) {
71+ return src;
72+ }
6373 const params = [` width=${ width} ` ];
6474 if (quality) {
6575 params .push (` quality=${ quality} ` );
0 commit comments