The Node.js® Website
at main 5.7 kB view raw
1'use strict'; 2 3import { withSentryConfig } from '@sentry/nextjs'; 4import withNextIntl from 'next-intl/plugin'; 5 6import { BASE_PATH, ENABLE_STATIC_EXPORT } from './next.constants.mjs'; 7import { redirects, rewrites } from './next.rewrites.mjs'; 8import { 9 SENTRY_DSN, 10 SENTRY_ENABLE, 11 SENTRY_EXTENSIONS, 12 SENTRY_TUNNEL, 13} from './sentry.constants.mjs'; 14 15/** @type {import('next').NextConfig} */ 16const nextConfig = { 17 // Just to ensure that React is always on strict mode 18 reactStrictMode: true, 19 // We intentionally disable Next.js's built-in i18n support 20 // as we dom have our own i18n and internationalisation engine 21 i18n: null, 22 // We want to always enforce that SWC minifies the sources even during Development mode 23 // so that bundles are minified on-the-go. SWF minifying is fast, and has almost no penalties 24 swcMinify: true, 25 // We don't use trailing slashes on URLs from the Node.js Website 26 trailingSlash: false, 27 // We don't want to redirect with trailing slashes 28 skipTrailingSlashRedirect: true, 29 // We allow the BASE_PATH to be overridden in case that the Website 30 // is being built on a subdirectory (e.g. /nodejs-website) 31 basePath: BASE_PATH, 32 images: { 33 // We disable image optimisation during static export builds 34 unoptimized: ENABLE_STATIC_EXPORT, 35 // We allow SVGs to be used as images 36 dangerouslyAllowSVG: true, 37 // We add it to the remote pattern for the static images we use from GitHub 38 remotePatterns: [ 39 { 40 protocol: 'https', 41 hostname: 'raw.githubusercontent.com', 42 port: '', 43 pathname: '/nodejs/**', 44 }, 45 { 46 protocol: 'https', 47 hostname: 'user-images.githubusercontent.com', 48 port: '', 49 pathname: '/**', 50 }, 51 { 52 protocol: 'https', 53 hostname: 'website-assets.oramasearch.com', 54 port: '', 55 pathname: '/**', 56 }, 57 ], 58 }, 59 // On static export builds we want the output directory to be "build" 60 distDir: ENABLE_STATIC_EXPORT ? 'build' : '.next', 61 // On static export builds we want to enable the export feature 62 output: ENABLE_STATIC_EXPORT ? 'export' : undefined, 63 // This configures all the Next.js rewrites, which are used for rewriting internal URLs into other internal Endpoints 64 // This feature is not supported within static export builds, hence we pass an empty array if static exports are enabled 65 rewrites: !ENABLE_STATIC_EXPORT ? rewrites : undefined, 66 // This configures all Next.js redirects 67 redirects: !ENABLE_STATIC_EXPORT ? redirects : undefined, 68 // We don't want to run Type Checking on Production Builds 69 // as we already check it on the CI within each Pull Request 70 typescript: { ignoreBuildErrors: true }, 71 // We don't want to run ESLint Checking on Production Builds 72 // as we already check it on the CI within each Pull Request 73 // we also configure ESLint to run its lint checking on all files (next lint) 74 eslint: { dirs: ['.'], ignoreDuringBuilds: true }, 75 // Adds custom WebPack configuration to our Next.hs setup 76 webpack: function (config, { webpack }) { 77 // Next.js WebPack Bundler does not know how to handle `.mjs` files on `node_modules` 78 // This is not an issue when using TurboPack as it uses SWC and it is ESM-only 79 // Once Next.js uses Turbopack for their build process we can remove this 80 config.module.rules.push({ 81 test: /\.m?js$/, 82 type: 'javascript/auto', 83 resolve: { fullySpecified: false }, 84 }); 85 86 // Tree-shakes modules from Sentry Bundle 87 config.plugins.push(new webpack.DefinePlugin(SENTRY_EXTENSIONS)); 88 89 return config; 90 }, 91 experimental: { 92 // Some of our static pages from `getStaticProps` have a lot of data 93 // since we pass the fully-compiled MDX page from `MDXRemote` through 94 // a page's static props. 95 largePageDataBytes: 128 * 100000, 96 // A list of packages that Next.js should automatically evaluate and optimise the imports for. 97 // @see https://vercel.com/blog/how-we-optimized-package-imports-in-next-js 98 optimizePackageImports: [ 99 '@radix-ui/react-avatar', 100 '@radix-ui/react-select', 101 '@radix-ui/react-toast', 102 'tailwindcss', 103 ], 104 // Removes the warning regarding the WebPack Build Worker 105 webpackBuildWorker: false, 106 }, 107}; 108 109/** @type {import('@sentry/cli').SentryCliOptions} */ 110const sentrySettings = { 111 // We don't want Sentry to emit logs 112 silent: true, 113 // Define the Sentry Organisation 114 org: 'nodejs-org', 115 // Define the Sentry Project on our Sentry Organisation 116 project: 'nodejs-org', 117 // Sentry DSN for the Node.js Website 118 dsn: SENTRY_DSN, 119}; 120 121/** @type {import('@sentry/nextjs/types/config/types').UserSentryOptions} */ 122const sentryConfig = { 123 // Upload Next.js or third-party code in addition to our code 124 widenClientFileUpload: true, 125 // Attempt to circumvent ad blockers 126 tunnelRoute: SENTRY_TUNNEL(), 127 // Prevent source map comments in built files 128 hideSourceMaps: false, 129 // Tree shake Sentry stuff from the bundle 130 disableLogger: true, 131 // Applies same WebPack Transpilation as Next.js 132 transpileClientSDK: true, 133}; 134 135// Next.js Configuration with `next.intl` enabled 136const nextWithIntl = withNextIntl('./i18n.tsx')(nextConfig); 137 138// Next.js Configuration with `sentry` enabled 139const nextWithSentry = withSentryConfig( 140 // Next.js Config with i18n Configuration 141 nextWithIntl, 142 // Default Sentry Settings 143 sentrySettings, 144 // Default Sentry Extension Configuration 145 sentryConfig 146); 147 148// Decides whether enabling Sentry or not 149// By default we only want to enable Sentry within a Vercel Environment 150export default SENTRY_ENABLE ? nextWithSentry : nextWithIntl;