Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What will happen if sourcemap is set as false in Angular

I'm new in Angular. I saw sourcemap in tsconfig.json and by default it is "sourceMap": true. I had few doubts and found this link useful. Still I have the following doubt regarding the same.

I set "sourceMap": false, but couldn't find any change in the app. What will be the actual change if I set so?

like image 475
kmg Avatar asked Feb 26 '19 06:02

kmg


People also ask

What is the use of Sourcemap in angular?

The source maps allow the compiled final output to be mapped to its original code before compilation. With the source maps, we can use a tool like source-map-explorer to inspect and show precisely what code is being sent to the client. To use Source Map Explorer, you will need to install via NPM.

What is Sourcemap in TypeScript?

Explanation: TypeScript Map files are source map files that let tools map between the emitted JavaScript code and the TypeScript source files that created it. And these Source Map files will then help to debug the Typescript file instead of debugging the emitted JavaScript file.

What is Sourcemap?

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. To enable the debugger to work with a source map, you must: generate the source map.

What is source map in angular JSON?

At its core, a source map is a JSON file that contains all the necessary information to map the transpiled code back to the original sources. Pretty cool! Technically a source map is just a JSON file that contains the following fields: version: indicates the source map spec version.


2 Answers

Nothing will change in how the app runs.

The change will be in your debugging experience.

Source maps are helpful for debugging code. You write your code in TypeScript, and the compiler turns that source code into JavaScript. When your app is running in a browser like Firefox, the browser is running the JavaScript. Even though the browser is running that JavaScript, if you open the debugger in Firefox, the debugger will display the TypeScript source code and will let you set break points in it. The debugger is able to do that because of source maps, which map the TypeScript source code to the JavaScript runtime code. That is what source maps do: they map the source code to the runtime code to enable source code debugging at runtime.

like image 77
Shaun Luttin Avatar answered Sep 20 '22 01:09

Shaun Luttin


sourceMap is just for development experience (debug) and normally you don't need these files in production build and if you check angular.json you will found that it 's set to false for you

  "configurations": {
    "production": {
      "fileReplacements": [
        {
          "replace": "src/environments/environment.ts",
          "with": "src/environments/environment.prod.ts"
        }
      ],
      "optimization": true,
      "outputHashing": "all",
      "sourceMap": false,  <----
      "extractCss": true,
      "namedChunks": false,
      "aot": true,
      "extractLicenses": true,
      "vendorChunk": false,
      "buildOptimizer": true
    }
like image 42
Muhammed Albarmavi Avatar answered Sep 20 '22 01:09

Muhammed Albarmavi