From 05b577e550c3a3d6c287e7e54e50d5c0897826bf Mon Sep 17 00:00:00 2001 From: Daniel Roe Date: Mon, 5 Jun 2023 19:23:38 +0100 Subject: [PATCH] fix(nuxt): support usage of `std-env` in runtime code (#21372) --- packages/nuxt/src/core/nuxt.ts | 5 ++++- packages/vite/src/client.ts | 1 + 2 files changed, 5 insertions(+), 1 deletion(-) diff --git a/packages/nuxt/src/core/nuxt.ts b/packages/nuxt/src/core/nuxt.ts index 16842c0f5f..defc1037e3 100644 --- a/packages/nuxt/src/core/nuxt.ts +++ b/packages/nuxt/src/core/nuxt.ts @@ -408,7 +408,10 @@ export async function loadNuxt (opts: LoadNuxtOptions): Promise { options._modules.push(schemaModule) options.modulesDir.push(resolve(options.workspaceDir, 'node_modules')) options.modulesDir.push(resolve(pkgDir, 'node_modules')) - options.build.transpile.push('@nuxt/ui-templates') + options.build.transpile.push( + '@nuxt/ui-templates', // this exposes vue SFCs + 'std-env' // we need to statically replace process.env when used in runtime code + ) options.alias['vue-demi'] = resolve(options.appDir, 'compat/vue-demi') options.alias['@vue/composition-api'] = resolve(options.appDir, 'compat/capi') if (options.telemetry !== false && !process.env.NUXT_TELEMETRY_DISABLED) { diff --git a/packages/vite/src/client.ts b/packages/vite/src/client.ts index 0cc57c6352..bcebae2c50 100644 --- a/packages/vite/src/client.ts +++ b/packages/vite/src/client.ts @@ -37,6 +37,7 @@ export async function buildClient (ctx: ViteBuildContext) { devSourcemap: ctx.nuxt.options.sourcemap.client }, define: { + 'process.env.NODE_ENV': JSON.stringify(ctx.config.mode), 'process.server': false, 'process.client': true, 'module.hot': false