-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathnext.config.ts
More file actions
104 lines (96 loc) · 2.46 KB
/
Copy pathnext.config.ts
File metadata and controls
104 lines (96 loc) · 2.46 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
import type { NextConfig } from 'next';
/** Matches `?url` (and `&url`) SVG import queries; shared by webpack and Turbopack. */
const svgUrlImportQuery = /[?&]url(?=&|$)/;
/** Turbopack: `?url` → asset URL; bare `.svg` → SVGR React component (matches webpack above). */
const platformSvgTurbopackRules: NonNullable<NextConfig['turbopack']>['rules'][string] = [
{
condition: { query: svgUrlImportQuery },
type: 'asset',
},
{
condition: { not: { query: svgUrlImportQuery } },
loaders: [
{
loader: '@svgr/webpack',
options: {
icon: true,
dimensions: false,
},
},
],
as: '*.js',
},
];
const nextConfig: NextConfig = {
output: 'standalone', // required for Docker (produces server.js)
// Mongoose/MongoDB use Node built-ins (net, tls, etc.); must not be webpack-bundled
// for instrumentation or other server entry points.
serverExternalPackages: ['mongoose', 'mongodb', 'ssh2'],
async headers() {
return [
{
source: '/:path*',
headers: [
{
key: 'Referrer-Policy',
value: 'strict-origin-when-cross-origin',
},
],
},
];
},
images: {
remotePatterns: [
{
protocol: 'https',
// R2 presigned URLs can be virtual-hosted style (e.g. bucket.account.r2...).
hostname: '**.r2.cloudflarestorage.com',
pathname: '/**',
},
],
},
webpack(config) {
const fileLoaderRule = config.module.rules.find(
(rule) =>
typeof rule === 'object' &&
rule !== null &&
'test' in rule &&
rule.test instanceof RegExp &&
rule.test.test('.svg')
);
if (!fileLoaderRule || typeof fileLoaderRule !== 'object') {
return config;
}
config.module.rules.push(
{
...fileLoaderRule,
test: /\.svg$/i,
resourceQuery: svgUrlImportQuery,
},
{
test: /\.svg$/i,
issuer: fileLoaderRule.issuer,
resourceQuery: {
not: [...(fileLoaderRule.resourceQuery?.not ?? []), svgUrlImportQuery],
},
use: [
{
loader: '@svgr/webpack',
options: {
icon: true,
dimensions: false,
},
},
],
}
);
fileLoaderRule.exclude = /\.svg$/i;
return config;
},
turbopack: {
rules: {
'*.svg': platformSvgTurbopackRules,
},
},
};
export default nextConfig;