Giter Site home page Giter Site logo

lucasklaassen / angular-rollbar-source-maps Goto Github PK

View Code? Open in Web Editor NEW
16.0 2.0 1.0 117 KB

Angular 2+ implementation to upload sourcemaps to Rollbar

License: MIT License

JavaScript 24.37% TypeScript 65.19% HTML 9.89% CSS 0.54%
angular angular6 angular2 angular3 angular4 angular5 rollbar sourcemaps angular7

angular-rollbar-source-maps's Introduction

Angular 6 Rollbar Source Maps

When you minify your javascript code with the Angular CLI it is hard to debug exceptions that arise in a production environment within Rollbar. Luckily for us, Rollbar allows us to upload our javascript source maps so that we can see the original source filename, line number, method name, and code snippet the exception occurred from.

Unfortunately for us, Rollbar does not have a streamlined process for uploading these source maps within an Angular 6 deployment pipeline. There is a webpack solution but this would require you to use ng eject to gain access to the webpack configuration file which shouldn't be necessary.

I built a script that can loop through the map files within your /dist folder and upload them to rollbar when you build your angular application. After the map files have been uploaded to Rollbar via their API, it wipes them out from the /dist folder so that you can deploy the entire /dist folder to production. (Although a user can deobfuscate your code without source maps, I recommend you always cover all of your bases)

.env

Be sure to update the .env file with your Rollbar Access Token as well as your websites main URL. Rollbar uses this URL to grab your minified javascript code to compare it with the source map we upload, so be sure that it's accurate.

npm run build

As you will see the package.json file the build command looks like so:

ts-node git.version.ts && ng build --prod --source-map && node scripts/sourceMap.js

Breakdown:

  1. ts-node git.version.ts This command takes the latest git commit SHA and creates a file named versions.ts within the environments folder. Rollbar requires you to attach a version number to each source map you upload so this implementation will work as you make changes down the line and run deploys. You'll notice we use this file within src/app/factories/rollbar.factory.ts where we define the rest of our settings we send to Rollbar.
  2. ng build --prod --source-map This command is pretty straightforward. It runs the classic ng build command and passes the production flag as well as a flag that tells the CLI to generate source maps.
  3. node scripts/sourceMap.js This is the script I have written which loops through all of the .map javascript files within the /dist folder and uploads them one by one to Rollbar via their API. After it's done uploading them to Rollbar it deletes them so that you don't deploy them to production.

Disclaimer

There are probably better ways to do this but at the time of me posting this, I was unable to find ANY resources out there to copy from. This repo was created in the hopes that it would help someone save a bit of time and provide a reference for one way to do this within an Angular 6 app.

angular-rollbar-source-maps's People

Contributors

lucasklaassen avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar

Forkers

geekbusinesslab

angular-rollbar-source-maps's Issues

Help. Interesting, I don't handle much node.

ts-node git.version.ts && ng build --prod --source-map && node scripts/sourceMap.js

C:\Users\user\AppData\Roaming\npm\node_modules\ts-node\src\index.ts:434
return new TSError(diagnosticText, diagnosticCodes)
^
TSError: ⨯ Unable to compile TypeScript:
git.version.ts:1:1 - error TS1202: Import assignment cannot be used when targeting ECMAScript modules. Consider using 'import * as ns from "mod"', 'import {a} from "mod"', 'import d from "mod"', or another module format instead.

1 import fs = require('fs');


  at createTSError (C:\Users\user\AppData\Roaming\npm\node_modules\ts-node\src\index.ts:434:12)
  at reportTSError (C:\Users\user\AppData\Roaming\npm\node_modules\ts-node\src\index.ts:438:19)
  at getOutput (C:\Users\user\AppData\Roaming\npm\node_modules\ts-node\src\index.ts:578:36)
  at Object.compile (C:\Users\user\AppData\Roaming\npm\node_modules\ts-node\src\index.ts:775:32)
  at Module.m._compile (C:\Users\user\AppData\Roaming\npm\node_modules\ts-node\src\index.ts:858:43)
  at Module._extensions..js (internal/modules/cjs/loader.js:712:10)
  at Object.require.extensions.(anonymous function) [as .ts] (C:\Users\user\AppData\Roaming\npm\node_modules\ts-node\src\index.ts:861:12)
  at Module.load (internal/modules/cjs/loader.js:600:32)
  at tryModuleLoad (internal/modules/cjs/loader.js:539:12)
  at Function.Module._load (internal/modules/cjs/loader.js:531:3)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.