From 8f0ff0d6c5823281766d8ba5382acabb1da74b27 Mon Sep 17 00:00:00 2001 From: Arick Date: Fri, 15 Sep 2023 15:25:32 +0800 Subject: [PATCH] chore: add option to serveFakeManifest --- packages/libs/s3-static-assets/src/index.ts | 6 ++++-- .../serverless-components/nextjs-component/src/component.ts | 3 ++- packages/serverless-components/nextjs-component/types.d.ts | 1 + 3 files changed, 7 insertions(+), 3 deletions(-) diff --git a/packages/libs/s3-static-assets/src/index.ts b/packages/libs/s3-static-assets/src/index.ts index 8986e9cf27..407e9bf156 100644 --- a/packages/libs/s3-static-assets/src/index.ts +++ b/packages/libs/s3-static-assets/src/index.ts @@ -23,6 +23,7 @@ type UploadStaticAssetsOptions = { credentials: Credentials; publicDirectoryCache?: PublicDirectoryCache; abTestPaths?: string[]; + serveFakeManifest?: boolean; }; /** @@ -38,7 +39,8 @@ const uploadStaticAssetsFromBuild = async ( credentials, basePath, publicDirectoryCache, - nextConfigDir + nextConfigDir, + serveFakeManifest } = options; const s3 = await S3ClientFactory({ bucketName, @@ -74,7 +76,7 @@ const uploadStaticAssetsFromBuild = async ( .filter(filterOutDirectories) .map(async (fileItem) => { console.info("static file path: ", fileItem.path); - if (fileItem.path.endsWith("_buildManifest.js")) { + if (serveFakeManifest && fileItem.path.endsWith("_buildManifest.js")) { console.info("clear _buildManifest.js"); fse.writeFileSync(fileItem.path, ""); } diff --git a/packages/serverless-components/nextjs-component/src/component.ts b/packages/serverless-components/nextjs-component/src/component.ts index 27f6cd99c3..dfa0604903 100644 --- a/packages/serverless-components/nextjs-component/src/component.ts +++ b/packages/serverless-components/nextjs-component/src/component.ts @@ -386,7 +386,8 @@ class NextjsComponent extends Component { nextStaticDir: nextStaticPath, credentials: this.context.credentials.aws, publicDirectoryCache: inputs.publicDirectoryCache, - abTestPaths + abTestPaths, + serveFakeManifest: inputs.serveFakeManifest ?? false }); } else { await uploadStaticAssets({ diff --git a/packages/serverless-components/nextjs-component/types.d.ts b/packages/serverless-components/nextjs-component/types.d.ts index 0019e7fe32..ba1ae5a895 100644 --- a/packages/serverless-components/nextjs-component/types.d.ts +++ b/packages/serverless-components/nextjs-component/types.d.ts @@ -64,6 +64,7 @@ export type ServerlessComponentInputs = { sentry?: SentryOptions; abTests?: ABTest[]; enableRemoteInvalidation?: boolean; + serveFakeManifest?: boolean; }; type CloudfrontOptions = Record;