Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to generate sourcemaps in create react app?

I'm wondering how to generate source maps in create-react-app? are they done implicitly? and do they live in the build folder

I've read quite a lot about them being generated with webpack but my app is not using it, so I was wondering how I do this without webpack?

I also don't want to eject

like image 446
Red Baron Avatar asked Apr 29 '19 13:04

Red Baron


People also ask

What are Sourcemaps react?

A sourcemap is a mapping between the generated/transpiled/minified JavaScript file and one or more original source files. The main purpose of sourcemaps is to aid debugging. Basically, if there's an error in the generated code file, the map can tell you the original source file location. That's it.

How do I enable source map in Create react app?

In the inspection tool, click on the gear icon on the very top right of the window to open the settings page as shown below. In the preference tab, under the Sources subheader, make sure that Enable JavaScript source maps is enabled.

What does generate source map do?

A source map is a file that maps from the transformed source to the original source, enabling the browser to reconstruct the original source and present the reconstructed original in the debugger.


1 Answers

According to CRA documentation, source maps are generated by default in production mode.

However, you can disable this behavior (generating source maps in production mode) by running GENERATE_SOURCEMAP=false ./node_modules/.bin/react-scripts build or if you want this behavior to be permanent, do one of the following solutions:

  1. Set GENERATE_SOURCEMAP=false in your .env file.
  2. Modify the scripts in your package.json and replace "build": "react-scripts build" with "build": "GENERATE_SOURCEMAP=false react-scripts build"

https://facebook.github.io/create-react-app/docs/advanced-configuration

like image 118
3b3ziz Avatar answered Sep 19 '22 08:09

3b3ziz