GKLBB

当你经历了暴风雨,你也就成为了暴风雨

导航

软件开发 --- 为什么我的生产环境web不打印日志

. 修复Vite配置以保留console日志
在 `vite.config.ts` 中进行了以下修改:

```
export default ({ mode }: ConfigEnv) => 
{
  // 判断是否为生产环境
  const isProduction = mode === 
  'production';
  
  return defineConfig({
    // ... 其他配置
    build: {
      minify: 'terser',
      outDir: ViteApp.VITE_OUTDIR,
      terserOptions: {
        // 根据环境决定是否移除console
        compress: {
          keep_infinity: true,
          // 只在生产环境移除console,开发
          和调试时保留
          drop_console: false// 改为
          false以保留console日志
          drop_debugger: 
          isProduction // 只在生产环境移除
          debugger
        }
      },
      // ...
    }
  });
};
```

 

posted on 2025-06-19 14:21  GKLBB  阅读(30)  评论(0)    收藏  举报