@@ -43,10 +43,12 @@ export function uploadcareLoader({
43
43
) ;
44
44
45
45
const proxy = trimTrailingSlash ( proxyEndpoint ) ;
46
+ const isProductionMode = isProduction ( ) ;
47
+ const isImageOnCdn = isCdnUrl ( src , cdnDomain ) ;
48
+ const isImageRelative = src . startsWith ( '/' ) ;
46
49
47
- const isOnCdn = isCdnUrl ( src , cdnDomain ) ;
48
-
49
- if ( ! isProduction ( ) && ! isOnCdn ) {
50
+ // Development mode; not on CDN.
51
+ if ( ! isProductionMode && ! isImageOnCdn ) {
50
52
const isPublicKeySet = ! isDotenvParamEmpty ( publicKey ) ;
51
53
const isCustomProxyEndpointSet = ! isDotenvParamEmpty ( customProxyEndpoint ) ;
52
54
@@ -56,34 +58,22 @@ export function uploadcareLoader({
56
58
) ;
57
59
}
58
60
59
- if ( src . startsWith ( '/' ) ) {
61
+ if ( isImageRelative ) {
60
62
return src ;
61
63
}
62
64
}
63
65
64
- // Process local images in Production.
65
- if ( isProduction ( ) && ! isOnCdn && src . startsWith ( '/' ) ) {
66
- const isBasePathSet = ! isDotenvParamEmpty ( basePath ) ;
67
-
68
- if ( ! isBasePathSet ) {
69
- return src ;
70
- }
71
-
72
- return `${ basePath } ${ src } ` ;
73
- }
74
-
75
66
const filename = getFilename ( src ) ;
76
67
const extension = getExtension ( filename ) ;
77
68
78
69
// Some extensions are not processed by Uploadcare, e.g. SVG.
79
70
if ( NOT_PROCESSED_EXTENSIONS . includes ( extension ) ) {
80
- return isOnCdn ? src : `${ basePath } ${ src } ` ;
71
+ return isImageOnCdn ? src : `${ basePath } ${ src } ` ;
81
72
}
82
73
83
74
// Demo: https://ucarecdn.com/a6f8abc8-f92e-460a-b7a1-c5cd70a18cdb/-/format/auto/-/resize/300x/vercel.png
84
75
85
76
const userParams = parseUserParamsString ( userParamsString ) ;
86
-
87
77
const requestedFormat = getRequestedFormatFromParams ( userParams ) ;
88
78
const qualityString = convertToUploadcareQualityString ( quality ) ;
89
79
@@ -101,10 +91,22 @@ export function uploadcareLoader({
101
91
102
92
const apiParamsString = '/-/' + params . join ( '/-/' ) + '/' ;
103
93
104
- if ( isOnCdn ) {
94
+ if ( isImageOnCdn ) {
105
95
const withoutFilename = src . slice ( 0 , src . lastIndexOf ( '/' ) ) ;
106
96
return `${ withoutFilename } ${ apiParamsString } ${ filename } ` ;
107
97
}
108
98
99
+ // Production mode; local image.
100
+ if ( isProductionMode && isImageRelative ) {
101
+ const isBasePathSet = ! isDotenvParamEmpty ( basePath ) ;
102
+
103
+ // Return the relative url AS IS if the base path is not set.
104
+ if ( ! isBasePathSet ) {
105
+ return src ;
106
+ }
107
+
108
+ return `${ proxy } ${ apiParamsString } ${ basePath } ${ src } ` ;
109
+ }
110
+
109
111
return `${ proxy } ${ apiParamsString } ${ src } ` ;
110
112
}
0 commit comments