Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to generate sourcemaps using Angular CLI and upload them to Sentry?

Tags:

There are two ways to set up sourcemaps: having them hosted on the site and referenced in the bundled files or uploading them directly to a service like sentry. I'm trying to accomplish the latter. The problem is that there seems to be no way to generate sourcemaps using angular cli without having the filepath written to the bundled files.

My first thought was to have two builds - one with sourcemaps generate and one without. I would then just deploy the build without sourcemaps and upload the build with them to sentry. That doesn't work because the bundle filenames are different (angular cli uses the file hash as the filename for cache busting and when you generate sourcemaps it adds the path to the .map file as a comment at the end causing a change in hash and filename).

My other option would be to build with sourcemaps, upload them to sentry, and then delete the map files before deploying the site. The problem there though is that the bundle files still contain a reference to a now non-existent map file. That shouldn't be an issue in and of itself but it might raise an issue with extensions or browsers down the line and just seems like a hackish solution.

How would you implementing something like this into the build process?

like image 769
Nikola Jankovic Avatar asked Sep 25 '18 02:09

Nikola Jankovic


People also ask

What is SourceMaps in angular?

source maps — a short introduction 💁🏻 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.

What is Sourcemappingurl?

The SourceMap HTTP response header links generated code to a source map, enabling the browser to reconstruct the original source and present the reconstructed original in the debugger.

How do I use source map in Explorer?

To use Source Map Explorer, you will need to install via NPM. Once installed, we can add it as an NPM stript to the package. json in our Angular application. When we run our script npm run bundle:report , we will get the output in the browser.


1 Answers

As mentioned in the comments, you can enable sourceMaps in the angular.json file like this:

 "configurations": {   "production": {     "sourceMap": {       "scripts": true,       "styles": true,       "hidden": true     }, 

Also, I recommend you remove the .map files after uploading to sentry and before deploying. So in your ci add this line:

rm -rf dist/YOUR_PROJECT/*.map 
like image 89
Vahid Avatar answered Oct 02 '22 22:10

Vahid