next.config.base.js 2.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586
  1. // @ts-check
  2. /**
  3. * @file Configure the Next.js build
  4. *
  5. * This file gets used by the Next.js build phase, and is not included in the
  6. * browser build. It will not be parsed by Webpack, Babel or TypeScript, so
  7. * don't use features that will not be available in our target node version.
  8. *
  9. * https://nextjs.org/docs/pages/api-reference/next-config-js
  10. */
  11. const { withSentryConfig } = require("@sentry/nextjs");
  12. const cp = require("child_process");
  13. const gitSHA = cp
  14. .execSync("git rev-parse --short HEAD", {
  15. cwd: __dirname,
  16. encoding: "utf8",
  17. })
  18. .trimEnd();
  19. /**
  20. * The base Next.js config. Before exporting this, we wrap this in
  21. * {@link withSentryConfig}.
  22. *
  23. * @type {import("next").NextConfig}
  24. */
  25. const nextConfig = {
  26. /* generate a static export when we run `next build` */
  27. output: "export",
  28. compiler: {
  29. emotion: true,
  30. },
  31. transpilePackages: [
  32. "@/next",
  33. "@/ui",
  34. "@/utils",
  35. "@mui/material",
  36. "@mui/system",
  37. "@mui/icons-material",
  38. ],
  39. // Add environment variables to the JavaScript bundle. They will be
  40. // available as `process.env.VAR_NAME` to our code.
  41. env: {
  42. GIT_SHA: gitSHA,
  43. },
  44. // https://dev.to/marcinwosinek/how-to-add-resolve-fallback-to-webpack-5-in-nextjs-10-i6j
  45. webpack: (config, { isServer }) => {
  46. if (!isServer) {
  47. config.resolve.fallback.fs = false;
  48. }
  49. return config;
  50. },
  51. // Build time Sentry configuration
  52. // https://docs.sentry.io/platforms/javascript/guides/nextjs/manual-setup/
  53. sentry: {
  54. widenClientFileUpload: true,
  55. disableServerWebpackPlugin: true,
  56. },
  57. };
  58. const sentryWebpackPluginOptions = {
  59. // The same release value needs to be used both:
  60. // 1. here to create a new release on Sentry and upload sourcemaps to it,
  61. // 2. and when initializing Sentry in the browser (`Sentry.init`).
  62. release: gitSHA,
  63. };
  64. // withSentryConfig extends the default Next.js usage of webpack to:
  65. //
  66. // 1. Initialize the SDK on client page load (See `sentry.client.config.ts`)
  67. //
  68. // 2. Upload sourcemaps, using the settings defined in `sentry.properties`.
  69. //
  70. // Sourcemaps are only uploaded to Sentry if SENTRY_AUTH_TOKEN is defined. Note
  71. // that sourcemaps are always generated in the static export; the Sentry Webpack
  72. // plugin behavies as if the `productionBrowserSourceMaps` Next.js configuration
  73. // setting is `true`.
  74. //
  75. // Irritatingly, Sentry insists that we create empty sentry.server.config.ts and
  76. // sentry.edge.config.ts files, even though we are not using those parts.
  77. module.exports = withSentryConfig(nextConfig, sentryWebpackPluginOptions);