|
1 | 1 | const fs = require('fs'); |
2 | 2 |
|
| 3 | +const SentryWebpackPlugin = require('@sentry/webpack-plugin'); |
| 4 | + |
3 | 5 | const sentryRelease = JSON.stringify( |
4 | 6 | // Always read first as Sentry takes this as precedence |
5 | 7 | process.env.SENTRY_RELEASE || |
@@ -29,6 +31,33 @@ exports.onCreateWebpackConfig = ({ plugins, getConfig, actions }) => { |
29 | 31 | ], |
30 | 32 | }); |
31 | 33 |
|
| 34 | + if (process.env.NODE_ENV === 'production') { |
| 35 | + actions.setWebpackConfig({ |
| 36 | + plugins: [ |
| 37 | + new SentryWebpackPlugin({ |
| 38 | + // Only include files from the build output directory |
| 39 | + include: 'public', |
| 40 | + // Ignore files that aren't users' source code related |
| 41 | + ignore: [ |
| 42 | + 'app-*', // related to Gatsby itself |
| 43 | + 'polyfill-*', // related to polyfills |
| 44 | + 'framework-*', // related to the frameworks (e.g. React) |
| 45 | + 'webpack-runtime-*', // related to Webpack |
| 46 | + ], |
| 47 | + // Handle sentry-cli configuration errors when the user has not done it not to break |
| 48 | + // the build. |
| 49 | + errorHandler(err, invokeErr) { |
| 50 | + const { message } = err; |
| 51 | + if (message.includes('organization slug is required') || message.includes('project slug is required')) { |
| 52 | + return; |
| 53 | + } |
| 54 | + invokeErr(err); |
| 55 | + }, |
| 56 | + }), |
| 57 | + ], |
| 58 | + }); |
| 59 | + } |
| 60 | + |
32 | 61 | // To configure the SDK, SENTRY_USER_CONFIG is prioritized over `gatsby-config.js`, |
33 | 62 | // since it isn't possible to set non-serializable parameters in the latter. |
34 | 63 | // Prioritization here means what `init` is run. |
|
0 commit comments