timarney / react-app-rewired

Override create-react-app webpack configs without ejecting
MIT License
9.79k stars 425 forks source link

how can i set GENERATE_SOURCEMAPS to false #533

Closed GreXLin85 closed 3 years ago

GreXLin85 commented 3 years ago

Normally im writing this command GENERATE_SOURCEMAP=false react-scripts build how can i do this in react-app-rewired

dawnmist commented 3 years ago

Two options.

  1. Do the exact same thing as you're already doing - i.e. GENERATE_SOURCEMAP=false react-app-rewired build, OR
  2. Put GENERATE_SOURCEMAP=false into your .env or .env.production file (the production one is for build only, whereas the one that is just .env will apply to production, test, and development) , which will then have it work every time for react-app-rewired and/or react-scripts without having to put it in the command line.

Environment variables specified on the command line are available for the build process to use.

GreXLin85 commented 3 years ago

Do the exact same thing as you're already doing - i.e. GENERATE_SOURCEMAP=false react-app-rewired build This is not working but i'll try another solution

dawnmist commented 3 years ago

I usually put either single or double quotes around the parameter value - which is the only thing I can think of for why it may not be working for you.

The other question would be what OS & shell are you using?

I have tested both options in my current project for work, though we've not yet moved from CRA3 to CRA4. I wouldn't have expected that to matter in terms of what is passed to the environment. I do know that some Windows shells have given us trouble in the past in some areas, hence why I was asking.

Current build script in the project I've just tested with, turning off sourcemaps, making the webpack runtime chunk a separate file for caching, and setting the build memory to 8Gb instead of 1.5Gb (typescript generics have in the past taken up a fair amount of memory to resolve during the build):

{
  "scripts": {
    "build": "GENERATE_SOURCEMAP='false' INLINE_RUNTIME_CHUNK='false' react-app-rewired --max-old-space-size=8192 build"
  }
}

Or alternatively defined in the .env file for turning off sourcemaps there:

// Generate source map files. Setting this to false in production mode can help reduce the build time,
// at the cost of making debugging harder as the javascript is uglified for production.
GENERATE_SOURCEMAP='false'

You only need it in one place or the other.

GreXLin85 commented 3 years ago

The other question would be what OS & shell are you using? I'm using Windows 10