2020-04-13 20:08:56 +02:00
|
|
|
// Use the hidden-source-map option when you don't want the source maps to be
|
|
|
|
// publicly available on the servers, only to the error reporting
|
2019-05-17 06:37:15 +02:00
|
|
|
const withSourceMaps = require('@zeit/next-source-maps')()
|
|
|
|
|
2020-04-13 20:08:56 +02:00
|
|
|
// Use the SentryWebpack plugin to upload the source maps during build step
|
|
|
|
const SentryWebpackPlugin = require('@sentry/webpack-plugin')
|
2020-05-02 07:07:31 +02:00
|
|
|
const {
|
|
|
|
SENTRY_DSN,
|
|
|
|
SENTRY_ORG,
|
|
|
|
SENTRY_PROJECT,
|
|
|
|
SENTRY_AUTH_TOKEN,
|
|
|
|
NODE_ENV,
|
|
|
|
} = process.env
|
2020-04-13 20:08:56 +02:00
|
|
|
|
2019-05-17 06:37:15 +02:00
|
|
|
module.exports = withSourceMaps({
|
2020-05-02 07:07:31 +02:00
|
|
|
env: {
|
|
|
|
SENTRY_DSN: process.env.SENTRY_DSN,
|
|
|
|
},
|
2019-11-06 18:32:28 +01:00
|
|
|
webpack: (config, options) => {
|
|
|
|
// In `pages/_app.js`, Sentry is imported from @sentry/node. While
|
|
|
|
// @sentry/browser will run in a Node.js environment, @sentry/node will use
|
|
|
|
// Node.js-only APIs to catch even more unhandled exceptions.
|
|
|
|
//
|
|
|
|
// This works well when Next.js is SSRing your page on a server with
|
|
|
|
// Node.js, but it is not what we want when your client-side bundle is being
|
|
|
|
// executed by a browser.
|
|
|
|
//
|
|
|
|
// Luckily, Next.js will call this webpack function twice, once for the
|
|
|
|
// server and once for the client. Read more:
|
|
|
|
// https://nextjs.org/docs#customizing-webpack-config
|
|
|
|
//
|
|
|
|
// So ask Webpack to replace @sentry/node imports with @sentry/browser when
|
|
|
|
// building the browser's bundle
|
|
|
|
if (!options.isServer) {
|
|
|
|
config.resolve.alias['@sentry/node'] = '@sentry/browser'
|
|
|
|
}
|
|
|
|
|
2020-04-13 20:08:56 +02:00
|
|
|
// When all the Sentry configuration env variables are available/configured
|
|
|
|
// The Sentry webpack plugin gets pushed to the webpack plugins to build
|
|
|
|
// and upload the source maps to sentry.
|
|
|
|
// This is an alternative to manually uploading the source maps
|
2020-05-02 07:07:31 +02:00
|
|
|
// Note: This is disabled in development mode.
|
|
|
|
if (
|
|
|
|
SENTRY_DSN &&
|
|
|
|
SENTRY_ORG &&
|
|
|
|
SENTRY_PROJECT &&
|
|
|
|
SENTRY_AUTH_TOKEN &&
|
|
|
|
NODE_ENV === 'production'
|
|
|
|
) {
|
2020-04-13 20:08:56 +02:00
|
|
|
config.plugins.push(
|
|
|
|
new SentryWebpackPlugin({
|
|
|
|
include: '.next',
|
|
|
|
ignore: ['node_modules'],
|
|
|
|
urlPrefix: '~/_next',
|
|
|
|
})
|
|
|
|
)
|
|
|
|
}
|
|
|
|
|
2019-11-06 18:32:28 +01:00
|
|
|
return config
|
2019-11-11 04:24:53 +01:00
|
|
|
},
|
2019-05-17 06:37:15 +02:00
|
|
|
})
|