diff --git a/packages/zip-it-and-ship-it/src/feature_flags.ts b/packages/zip-it-and-ship-it/src/feature_flags.ts index cfadaea38f..53d7380ab7 100644 --- a/packages/zip-it-and-ship-it/src/feature_flags.ts +++ b/packages/zip-it-and-ship-it/src/feature_flags.ts @@ -29,6 +29,9 @@ export const defaultFlags = { // Adds the `___netlify-telemetry.mjs` file to the function bundle. zisi_add_instrumentation_loader: true, + + // Dynamically import the function handler. + zisi_dynamic_import_function_handler: false, } as const export type FeatureFlags = Partial> diff --git a/packages/zip-it-and-ship-it/src/runtimes/node/utils/entry_file.ts b/packages/zip-it-and-ship-it/src/runtimes/node/utils/entry_file.ts index 837cbe8def..06d4d50583 100644 --- a/packages/zip-it-and-ship-it/src/runtimes/node/utils/entry_file.ts +++ b/packages/zip-it-and-ship-it/src/runtimes/node/utils/entry_file.ts @@ -51,6 +51,12 @@ const getEntryFileContents = ( const importPath = `.${mainPath.startsWith('/') ? mainPath : `/${mainPath}`}` if (runtimeAPIVersion === 2) { + if (featureFlags.zisi_dynamic_import_function_handler) { + return [ + `import * as bootstrap from './${BOOTSTRAP_FILE_NAME}'`, + `export const handler = bootstrap.getLambdaHandler('${importPath}')`, + ].join(';') + } return [ `import * as bootstrap from './${BOOTSTRAP_FILE_NAME}'`, `import * as func from '${importPath}'`,