From c3f771fec844b3fe936c9e2f72b3f26a5b141437 Mon Sep 17 00:00:00 2001 From: Yuanlin Lin Date: Wed, 9 Mar 2022 18:02:55 +0800 Subject: [PATCH] feat(api-routes-vercel): Check there is vercel.json if user want to use API routes in vercel (#452) --- .../preset-umi/src/features/apiRoute/apiRoute.ts | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) diff --git a/packages/preset-umi/src/features/apiRoute/apiRoute.ts b/packages/preset-umi/src/features/apiRoute/apiRoute.ts index 429d31236abc..2859d3cc2742 100644 --- a/packages/preset-umi/src/features/apiRoute/apiRoute.ts +++ b/packages/preset-umi/src/features/apiRoute/apiRoute.ts @@ -76,6 +76,22 @@ export default (api: IApi) => { return false; } + // 如果是 Vercel 平台,则需要检查是否有配置了 Vercel 配置 + if (!fs.existsSync(join(api.paths.cwd, 'vercel.json'))) { + logger.warn( + 'You have enabled the API route feature, but there is no vercel.json file in your work directory! ' + + 'Automatically creating a vercel.json file ...', + ); + fs.writeFileSync( + join(api.paths.cwd, 'vercel.json'), + JSON.stringify( + { build: { env: { ENABLE_FILE_SYSTEM_API: '1' } } }, + null, + 2, + ), + ); + } + return true; }, });