From 342429934a87a6b291524e97d009b27547072f53 Mon Sep 17 00:00:00 2001 From: yjl9903 Date: Thu, 3 Oct 2024 00:45:42 +0800 Subject: [PATCH] feat: disable env in cloudflare --- README.md | 2 +- src/core/modules/env.ts | 8 +++++--- src/core/types.ts | 8 ++++++++ 3 files changed, 14 insertions(+), 4 deletions(-) diff --git a/README.md b/README.md index c702d82..cac6263 100644 --- a/README.md +++ b/README.md @@ -268,7 +268,7 @@ import { // ... ``` -> **Notice** +> [!NOTE] > > From `unplugin-info@0.6.0`, the original virtual module called `~build/info` will be renamed to `~build/git`, and the CI/CD related information will be moved to another virtual module called `~build/ci`. diff --git a/src/core/modules/env.ts b/src/core/modules/env.ts index 664af8e..d675b77 100644 --- a/src/core/modules/env.ts +++ b/src/core/modules/env.ts @@ -15,10 +15,12 @@ export class BuildEnvModule extends BuildInfoModule { return options.env; }; + const cloudflare = options.cloudflare === true; const meta = await get(); - const body = Object.entries(meta).map( - ([key, value]) => - `export const ${key} = (import.meta.env.SSR ? process?.env?.['${key.replace(/'/g, '\\')}'] : undefined) ?? ${JSON.stringify(value, null, 2)};` + const body = Object.entries(meta).map(([key, value]) => + !cloudflare + ? `export const ${key} = (import.meta.env.SSR ? process?.env?.['${key.replace(/'/g, '\\')}'] : undefined) ?? ${JSON.stringify(value, null, 2)};` + : `export const ${key} = ${JSON.stringify(value, null, 2)};` ); return body.length > 0 ? body.join('\n') : 'export {};'; diff --git a/src/core/types.ts b/src/core/types.ts index 1eec611..9980cac 100644 --- a/src/core/types.ts +++ b/src/core/types.ts @@ -65,6 +65,9 @@ export interface Options { */ env?: Metadata | (() => Env | Promise); + /** + * Print help build information + */ console?: { /** * Enable build info log under these NODE_ENV @@ -80,4 +83,9 @@ export interface Options { * @default '~build' */ prefix?: string; + + /** + * Whether it is bundled for cloudflare worker runtime + */ + cloudflare?: boolean; }