You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

React项目无法禁用Source Maps,配置修改后问题仍未解决

Fixing Source Maps Not Disabling & .env File Tracking Issues

Hey there, let's work through these two problems step by step!

1. Getting Source Maps Properly Disabled

It sounds like your build config changes aren't taking effect—here are targeted fixes based on common frameworks:

  • For Vite projects:
    Open your vite.config.js/vite.config.ts and ensure this setting is present:

    export default defineConfig({
      build: {
        sourcemap: false, // Disables source maps for production builds
      },
    })
    
  • For Create React App (CRA):
    Add this line to your .env or .env.production file:

    GENERATE_SOURCEMAP=false
    

    Don’t forget to restart your dev server if testing locally, and always rebuild with npm run build after updating this setting.

  • For Vue CLI projects:
    Update your vue.config.js with this configuration:

    module.exports = {
      productionSourceMap: false, // Turns off source maps in production builds
    }
    
  • Post-config verification steps:

    • Delete your entire dist (or build output) folder before rebuilding—old source map files might still linger and get deployed.
    • After building, check the output folder for any .map files. If they’re still there, double-check your config for typos (like mixing up sourcemap vs sourceMap in some frameworks).
    • Confirm your deployment process isn’t uploading leftover .map files. Many hosting platforms deploy all files in the build folder, so make sure these files are gone before pushing changes.

2. Making Git Track Your .env File

If your .env file is showing as untracked, it’s almost certainly because it’s listed in your .gitignore file. Here’s how to resolve this:

  • First, check your .gitignore for lines like .env, .env.local, or .env.*—these rules tell Git to ignore these files by default.
  • If you need to track a specific .env file (like .env.production—never track files with sensitive keys like API secrets!), add an exception to .gitignore:
    # Ignore most .env files by default
    .env
    .env.local
    # Allow tracking .env.production
    !.env.production
    
  • To confirm which rule is ignoring your file, run this terminal command:
    git check-ignore -v .env
    
    It will show you exactly which line in .gitignore is causing the file to be skipped.
  • Finally, stage the file with Git:
    git add .env
    
    You should now be able to commit it normally.

A quick reminder: Only commit .env files that don’t contain sensitive information (like API keys or database passwords). For local development, use .env.local which should stay in .gitignore to keep secrets safe.

内容的提问来源于stack exchange,提问作者Yahia Naguib

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.05.13 07:33:04