next.config.js 2.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869
  1. const withBundleAnalyzer = require('@next/bundle-analyzer')({
  2. enabled: process.env.ANALYZE === 'true',
  3. });
  4. const { withSentryConfig } = require('@sentry/nextjs');
  5. const { PHASE_DEVELOPMENT_SERVER } = require('next/constants');
  6. const withTM = require('next-transpile-modules')([
  7. '@mui/material',
  8. '@mui/system',
  9. '@mui/icons-material',
  10. ]);
  11. const {
  12. getGitSha,
  13. convertToNextHeaderFormat,
  14. buildCSPHeader,
  15. COOP_COEP_HEADERS,
  16. WEB_SECURITY_HEADERS,
  17. CSP_DIRECTIVES,
  18. ALL_ROUTES,
  19. getIsSentryEnabled,
  20. } = require('./configUtil');
  21. const GIT_SHA = getGitSha();
  22. const IS_SENTRY_ENABLED = getIsSentryEnabled();
  23. module.exports = (phase) =>
  24. withSentryConfig(
  25. withBundleAnalyzer(
  26. withTM({
  27. compiler: {
  28. styledComponents: {
  29. ssr: true,
  30. displayName: true,
  31. },
  32. },
  33. env: {
  34. SENTRY_RELEASE: GIT_SHA,
  35. },
  36. headers() {
  37. return [
  38. {
  39. // Apply these headers to all routes in your application....
  40. source: ALL_ROUTES,
  41. headers: convertToNextHeaderFormat({
  42. ...COOP_COEP_HEADERS,
  43. ...WEB_SECURITY_HEADERS,
  44. ...buildCSPHeader(CSP_DIRECTIVES),
  45. }),
  46. },
  47. ];
  48. },
  49. // https://dev.to/marcinwosinek/how-to-add-resolve-fallback-to-webpack-5-in-nextjs-10-i6j
  50. webpack: (config, { isServer }) => {
  51. if (!isServer) {
  52. config.resolve.fallback.fs = false;
  53. }
  54. return config;
  55. },
  56. })
  57. ),
  58. {
  59. release: GIT_SHA,
  60. dryRun: phase === PHASE_DEVELOPMENT_SERVER || !IS_SENTRY_ENABLED,
  61. }
  62. );