-
I met
source-map
Generally, the code we package to the server is compressed and uglified. Some projects will be configured with a browser-compatible plug-in
es6
Code to convert toes5
In this way, if the project deployed to the test server has problems during development and debugging, we cannot locate the problem well as shown in the following figure:source-map
This will help you to locate the wrong line of code in that file, if the project is configured with some willes6
Write code to convert toes5
Plug-in for codesource-map
The ability to map converted code to the original file allows the browser to refactor the original source and display the rebuilt original source in the debugger; The effect is as follows: -
use
source-map
在
webpack
Adding to the configurationdevtool
Detailed configurations are described in the following figure:If the configuration content issource-map
Is generated according to the source filesource-map
File and there’s a comment on the last line of the packaged code that points to the correspondingsource-map
The diagram below:At the same timeChrome
Also add the following two items (which are checked by default) to the Settings of: -
devtool
configurationSo we talked about use
source-map
withdevtool
Configuration, here are some configuration options-
Will not generate
source-map
Several configurations offalse
: do not usesource-map
(none)
Recommended for production environment: Do not writedevtool
The configuration,mode
isproduction
The default in the case of(none)
eval
:mode
isdevelpment
In the case of default values, will not be generatedsource-map
File, it will be ineval
Execute code to add//# sourceURL=
Comments, and debugging can also locate the code:
Can also locate the wrong location:
-
source-map
Generate corresponding
source-map
File and adds a comment to the last line of the packaged code//#sourceMappingURL=build.js.map
-
eval-source-map
Will be generated
source-map
But instead of creating a new file, it willDataUrl
Added to theeval
The following function looks like this: -
cheap-source-map
和
source-map
It’s going to generate onesource-map
File and the packaged file will have a comment on the last line pointing to the correspondingsource-map
File, but on browser error alertscheap-source-map
Only prompt to row, not exactly to the corresponding column as shown in the figure below: -
inline-source-map
Will not generate
source-map
File but the correspondingsource-map
Will be followed by the package fileDataUrl
Added to thebundle
The rest of the file looks like this:
-
-
nosources-source-map
Will be generated
sourcemap
, but generatedsourcemap
Only error messages are displayed, and no source code files are generated. The diagram below: -
hidden-source-map
Will be generated
sourcemap
, also generates the corresponding file, but will not add comments to the last line of the package file, so want to usesource-map
You need to add your own comments as shown below: -
cheap-module-source-map
(Recommended in development mode)If some projects use some
loader
Such asbabel-loader
Some manipulation of the source code that we just usecheap-source-map
The debugging effects are as follows:The source code has this error on line 5 but this error is on line 4 becausebabel
I did a little bit of translation to the source code so it’s going to be a little bit different than the source code. But if you usecheap-module-source-map
The effect is as follows:This configuration is recommended in development mode because the discovery can accurately locate lines of code -
The combined value
Combination rules:
inline-|hidden-|eval
: When there are three values, choose one of three;nosources
: optional valuecheap
Optional value and can be followedmodule
The value of the
The combined equation is as follows:
[inline-|hidden-|eval-][nosources-][cheap-[module-]]source-map
-
A variety of
source-map
Performance: