If source-map is enabled, the build speed will be slow.

So take a look at what source-map is.

What is the Source map

  • Source map, the name of which has basically explained its specific principle — in some way, the compressed and compiled online files are mapped to the source file.
  • Source mapping: A separate Sourcemap file is generated, and errors are identified by the column and row that are currently reporting an error.

Applicable scenarios of Source Map:

  • Code compression (compress/uglify etc.)
  • Multi-file merging (to reduce HTTP requests)
  • Language preprocessing, compilation, etc. (COMPILE es6, JSX to ES5, compile TypeScript to JavaScript, etc.)

Why open source Map

  • When there is an error in the file and the mode used is Production, the packaged file is in a compressed form, so it is difficult to locate the error. Source-map is a mapping file. If you click on it, the error is the source code, not the compressed format, which is convenient for debugging.

The source map form

There are four main forms that need to be added to the configuration file webpack.config.js:

  1. Add mapping files to help us debug the source code

     devtool:'source-map'
    Copy the code
  2. No separate files are generated, but rows and columns can be displayed

     devtool: 'eval-source-map'
    Copy the code
  3. No columns are generated, but it is a separate mapping file that can be retained for debugging

    Devtool: 'cheap-module-source-map' // not much useCopy the code
  4. Instead of generating a file, it is integrated into a packaged file and produces no columns

     devtool:'cheap-module-eval-source-map'
     
    Copy the code
  5. Cancel the mapping

     devtool:false
    Copy the code

React-scripts wepack.config.js source map configuration:

A new mapping file will be added under the packaged directory build:

Open source Map and see the source file in your browser

When you close Source Map, you cannot see the source file, only the compressed file

Reference documentation

  • To configure the source – the map
  • source-map
  • What are the 7 SourceMap modes in Devtool