@@ -7,6 +7,7 @@ import { join, relative, resolve } from 'pathe'
7
7
import { HANDLER_FUNCTION_NAME , ODB_FUNCTION_NAME , IMAGE_FUNCTION_NAME , DEFAULT_FUNCTIONS_SRC } from '../constants'
8
8
import { getHandler } from '../templates/getHandler'
9
9
import { getPageResolver } from '../templates/getPageResolver'
10
+ import { isEnvSet } from './utils'
10
11
11
12
export const generateFunctions = async (
12
13
{ FUNCTIONS_SRC = DEFAULT_FUNCTIONS_SRC , INTERNAL_FUNCTIONS_SRC , PUBLISH_DIR } : NetlifyPluginConstants ,
@@ -69,35 +70,39 @@ export const setupImageFunction = async ({
69
70
remotePatterns : RemotePattern [ ]
70
71
responseHeaders ?: Record < string , string >
71
72
} ) : Promise < void > => {
72
- const functionsPath = INTERNAL_FUNCTIONS_SRC || FUNCTIONS_SRC
73
- const functionName = `${ IMAGE_FUNCTION_NAME } .js`
74
- const functionDirectory = join ( functionsPath , IMAGE_FUNCTION_NAME )
75
-
76
- await ensureDir ( functionDirectory )
77
- await writeJSON ( join ( functionDirectory , 'imageconfig.json' ) , {
78
- ...imageconfig ,
79
- basePath : [ basePath , IMAGE_FUNCTION_NAME ] . join ( '/' ) ,
80
- remotePatterns,
81
- responseHeaders,
82
- } )
83
- await copyFile ( join ( __dirname , '..' , '..' , 'lib' , 'templates' , 'ipx.js' ) , join ( functionDirectory , functionName ) )
73
+
74
+ if ( ! isEnvSet ( 'DISABLE_IPX' ) ) {
75
+ const functionsPath = INTERNAL_FUNCTIONS_SRC || FUNCTIONS_SRC
76
+ const functionName = `${ IMAGE_FUNCTION_NAME } .js`
77
+ const functionDirectory = join ( functionsPath , IMAGE_FUNCTION_NAME )
84
78
85
- const imagePath = imageconfig . path || '/_next/image'
79
+ await ensureDir ( functionDirectory )
80
+ await writeJSON ( join ( functionDirectory , 'imageconfig.json' ) , {
81
+ ...imageconfig ,
82
+ basePath : [ basePath , IMAGE_FUNCTION_NAME ] . join ( '/' ) ,
83
+ remotePatterns,
84
+ responseHeaders,
85
+ } )
86
+
87
+ await copyFile ( join ( __dirname , '..' , '..' , 'lib' , 'templates' , 'ipx.js' ) , join ( functionDirectory , functionName ) )
86
88
87
- // If we have edge functions then the request will have already been rewritten
88
- // so this won't match. This is matched if edge is disabled or unavailable.
89
- netlifyConfig . redirects . push ( {
90
- from : `${ imagePath } *` ,
91
- query : { url : ':url' , w : ':width' , q : ':quality' } ,
92
- to : `${ basePath } /${ IMAGE_FUNCTION_NAME } /w_:width,q_:quality/:url` ,
93
- status : 301 ,
94
- } )
89
+ const imagePath = imageconfig . path || '/_next/image'
95
90
96
- netlifyConfig . redirects . push ( {
97
- from : `${ basePath } /${ IMAGE_FUNCTION_NAME } /*` ,
98
- to : `/.netlify/builders/${ IMAGE_FUNCTION_NAME } ` ,
99
- status : 200 ,
100
- } )
91
+ // If we have edge functions then the request will have already been rewritten
92
+ // so this won't match. This is matched if edge is disabled or unavailable.
93
+ netlifyConfig . redirects . push ( {
94
+ from : `${ imagePath } *` ,
95
+ query : { url : ':url' , w : ':width' , q : ':quality' } ,
96
+ to : `${ basePath } /${ IMAGE_FUNCTION_NAME } /w_:width,q_:quality/:url` ,
97
+ status : 301 ,
98
+ } )
99
+
100
+ netlifyConfig . redirects . push ( {
101
+ from : `${ basePath } /${ IMAGE_FUNCTION_NAME } /*` ,
102
+ to : `/.netlify/builders/${ IMAGE_FUNCTION_NAME } ` ,
103
+ status : 200 ,
104
+ } )
105
+ }
101
106
102
107
if ( basePath ) {
103
108
// next/image generates image static URLs that still point at the site root
0 commit comments