From a93f476e46c62a880c879cae59469b5069f66b6c Mon Sep 17 00:00:00 2001 From: hailin Date: Sun, 15 Jun 2025 21:29:38 +0800 Subject: [PATCH] . --- apps/blogai/app/[locale]/layout.tsx | 3 ++- .../components/dev-only/console-silencer.tsx | 17 +++++++++++++++++ apps/blogai/next.config.js | 10 +++++----- 3 files changed, 24 insertions(+), 6 deletions(-) create mode 100644 apps/blogai/components/dev-only/console-silencer.tsx diff --git a/apps/blogai/app/[locale]/layout.tsx b/apps/blogai/app/[locale]/layout.tsx index 3ae813c..4aa82f8 100644 --- a/apps/blogai/app/[locale]/layout.tsx +++ b/apps/blogai/app/[locale]/layout.tsx @@ -19,6 +19,7 @@ import { dir } from 'i18next'; import { ReactNode } from 'react'; import TranslationsProvider from '@/components/TranslationsProvider'; import initTranslations from '../i18n'; +import { ConsoleSilencer } from '@/components/dev-only/console-silencer' export const runtime = 'edge' // 'nodejs' (default) | 'edge' @@ -68,7 +69,6 @@ export default async function RootLayout({ children: ReactNode; params: { locale: string }; }) { - const { t, resources } = await initTranslations(locale, i18nNamespaces); return ( @@ -93,6 +93,7 @@ export default async function RootLayout({ resources={resources}> +
{/*
*/} diff --git a/apps/blogai/components/dev-only/console-silencer.tsx b/apps/blogai/components/dev-only/console-silencer.tsx new file mode 100644 index 0000000..a5d33cc --- /dev/null +++ b/apps/blogai/components/dev-only/console-silencer.tsx @@ -0,0 +1,17 @@ +'use client' + +import { useEffect } from 'react' + +export function ConsoleSilencer() { + useEffect(() => { + if (process.env.NODE_ENV === 'development') { + console.log = () => {}; + console.debug = () => {}; + console.info = () => {}; + console.warn = () => {}; + console.error = () => {}; + } + }, []) + + return null +} diff --git a/apps/blogai/next.config.js b/apps/blogai/next.config.js index 0564b02..1196206 100644 --- a/apps/blogai/next.config.js +++ b/apps/blogai/next.config.js @@ -17,8 +17,8 @@ const nextConfig = { esmExternals: "loose", }, compiler: { - removeConsole: false, // 保留所有模式中的 console.log - //removeConsole: process.env.VERCEL_ENV === 'production' ? { exclude: ['error'] } : false, + //removeConsole: false, // 保留所有模式中的 console.log + removeConsole: process.env.NODE_ENV === 'production' ? { exclude: ['error'] } : false, // ✅ 用 NODE_ENV emotion: true, }, webpack: (config, { isServer }) => { @@ -52,9 +52,9 @@ const nextConfig = { // your project has ESLint errors. ignoreDuringBuilds: true, }, - experimental: { - esmExternals: true, - }, + // experimental: { + // esmExternals: true, + // }, images: { remotePatterns: [ {