Install the plugin with npm:
npm install rollbar-sourcemap-webpack-plugin --save-dev
An example webpack.config.js:
const RollbarSourceMapPlugin =const PUBLIC_PATH = ''const webpackConfig =mode: 'production'devtool: 'hidden-source-map'entry: 'index'publicPath: PUBLIC_PATHoutput:path: 'dist'filename: 'index-[hash].js'plugins:accessToken: 'aaaabbbbccccddddeeeeffff00001111'version: 'version_string_here'publicPath: PUBLIC_PATH
You can pass a hash of configuration options to
Allowed values are as follows:
accessToken: string (required)
post_server_item access token.
version: string (required)
A string identifying the version of your code this source map package is for. Typically this will be the full git sha.
publicPath: string | function(string): string (required)
The base url for the cdn where your production bundles are hosted or a function that receives the source file local address and returns the url for that file in the cdn where your production bundles are hosted.
You should use the function form when your project has some kind of divergence between url routes and actual folder structure.
For example: NextJs projects can serve bundled files in the following url
http://my.app/_next/123abc123abc123/page/home.js but have a folder structure like this
The function form allows you to transform the final public url in order to conform with your routing needs.
includeChunks: string | [string] (optional)
An array of chunks for which sourcemaps should be uploaded.
This should correspond to the names in the webpack config
If there's only one chunk, it can be a string rather than an array.
If not supplied, all sourcemaps emitted by webpack will be uploaded, including those for unnamed chunks.
silent: boolean (default:
false, success and warning messages will be logged to the console for each upload. Note: if you also do not want to see errors, set the
ignoreErrors option to
ignoreErrors: boolean (default:
true to bypass adding upload errors to the webpack compilation. Do this if you do not want to fail the build when sourcemap uploads fail.
If you do not want to fail the build but you do want to see the failures as warnings, make sure
silent option is set to
rollbarEndpoint: string (default:
A string defining the Rollbar API endpoint to upload the sourcemaps to. It can be used for self-hosted Rollbar instances.
Webpack Sourcemap Configuration
output.devtool field in webpack configuration controls how sourcemaps are generated.
The recommended setup for sourcemaps in a production app is to use hidden sourcemaps.
hidden prefix will prevent
This is important because if the
sourceMappingURL comment is present,
Rollbar will attempt to download the sourcemap from this url, which negates the whole
purpose of this plugin. And since you are not uploading sourcemaps to a public location,
Rollbar would not be able to download the sourcemaps.
- The web app should have Rollbar.js installed and configured for webpack as described here.
- See the Rollbar source map documentation
for how to configure the client side for sourcemap support.
code_versionparameter must match the
versionparameter used for the plugin.
- More general info on the using Rollbar for browser JS.
See the Contributors Guide