Repository navigation
Expand file tree
/
Copy pathnext.config.js
More file actions
117 lines (106 loc) · 4.57 KB
/
Copy pathnext.config.js
File metadata and controls
117 lines (106 loc) · 4.57 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
const withBundleAnalyzer = require('@next/bundle-analyzer')({
enabled: process.env.BUNDLE_ANALYZER === 'true',
});
// Destination of the generated nextjs-routes.d.ts. It has to be passed to nextjs-routes twice:
// the webpack plugin below takes it as an option, while the CLI (pnpm routes:generate) only reads
// it off the resolved Next.js config, hence the `outDir` key at the bottom of moduleExports.
const ROUTES_OUT_DIR = 'src/shared/router';
const withRoutes = require('nextjs-routes/config')({
outDir: ROUTES_OUT_DIR,
});
const headers = require('./src/server/headers');
const redirects = require('./src/server/redirects');
const rewrites = require('./src/server/rewrites');
/** @type {import('next').NextConfig} */
const moduleExports = {
transpilePackages: [
'react-syntax-highlighter',
],
reactStrictMode: true,
// Turbopack config (Next.js 16 default bundler) – mirrors webpack customizations below
turbopack: {
rules: {
'*.svg': {
loaders: [ '@svgr/webpack' ],
as: '*.js',
},
},
// Stub Node built-ins only in browser bundles; Node (SSR, instrumentation) keeps real modules
resolveAlias: {
fs: { browser: './src/server/empty-module.js' },
net: { browser: './src/server/empty-module.js' },
tls: { browser: './src/server/empty-module.js' },
},
},
// Used when BUNDLE_ANALYZER=true (run: next build --webpack) or for custom webpack tooling
webpack(config) {
config.module.rules.push(
{
test: /\.svg$/,
use: [ '@svgr/webpack' ],
},
);
config.resolve.fallback = {
fs: false,
net: false,
tls: false,
// @metamask/sdk (reached via @wagmi/connectors -> @reown/appkit-adapter-wagmi) imports the
// React Native storage adapter unconditionally. It is an optional peer dep of a code path a
// browser bundle never takes, so resolve it to an empty module instead of letting webpack
// warn about it on every production build.
'@react-native-async-storage/async-storage': false,
};
config.externals.push('pino-pretty', 'lokijs', 'encoding');
config.experiments = { ...config.experiments, topLevelAwait: true };
// Tell webpack the target supports async/await so it stops warning about top-level await
// Top-level await is belong to ES2017 specification that is adopted by all major browsers and Node.js.
config.output.environment = {
...config.output.environment,
asyncFunction: true,
};
return config;
},
// NOTE: all config functions should be static and not depend on any environment variables
// since all variables will be passed to the app only at runtime and there is now way to change Next.js config at this time
// if you are stuck and strongly believe what you need some sort of flexibility here please fill free to join the discussion
// https://github.com/blockscout/frontend/discussions/167
rewrites,
redirects,
headers,
output: 'standalone',
// Turbopack's standalone tracer copies only @swc/helpers/cjs and drops the esm/ entry points that
// Next's require-hook loads at runtime, so `node server.js` crashes on boot. Force the whole
// package into the standalone bundle until the tracer is fixed upstream.
outputFileTracingIncludes: {
'/**': [ './node_modules/@swc/helpers/**' ],
},
productionBrowserSourceMaps: false,
serverExternalPackages: [
'@opentelemetry/sdk-node',
'@opentelemetry/auto-instrumentations-node',
'pino-pretty',
'lokijs',
'encoding',
],
experimental: {
staleTimes: {
dynamic: 30,
'static': 180,
},
// Next 16.4 turned the Turbopack shared runtime on by default. In production it replaces the per-route
// runtime chunk with an inline bootstrap <script> that carries neither a nonce nor a hash, so the strict
// script-src in src/server/csp blocks it and the page never hydrates. Keep the per-route chunk instead.
// Upstream: https://github.com/vercel/next.js/pull/100102 (app router only), https://github.com/vercel/next.js/pull/97574
turbopackSharedRuntime: false,
},
// Type-checking is done by `pnpm lint:tsc` (TypeScript 7), not by Next: Next resolves the
// `typescript` package, which here is the TS 6 alias — see .agents/adr/0004-typescript-7-side-by-side.md.
typescript: {
ignoreBuildErrors: true,
},
// workaround for passing outDir to nextjs-routes CLI, see ROUTES_OUT_DIR above.
// Next.js warns about this unrecognized key on startup; the warning is harmless.
outDir: ROUTES_OUT_DIR,
agentRules: false
};
module.exports = withBundleAnalyzer(withRoutes(moduleExports));