-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathnext.config.js
More file actions
171 lines (167 loc) · 5.75 KB
/
Copy pathnext.config.js
File metadata and controls
171 lines (167 loc) · 5.75 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
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
const dotenv = require('dotenv');
const path = require('path');
const { existsSync } = require('fs');
const withBundleAnalyzer = require('@next/bundle-analyzer')({
enabled: process.env.ANALYZE === 'true',
});
module.exports = withBundleAnalyzer({
// Move env loading to the top level, outside the config
...loadEnv(),
i18n: {
locales: ['en', 'ru', 'hy'],
defaultLocale: 'en',
},
async rewrites() {
return [
// Legacy prefix strip — both repos used to namespace public/ with
// /keepsimple_/* and /uxcore_/* respectively. Public is now flat, so any
// straggler path with those prefixes resolves to the bare equivalent.
{ source: '/keepsimple_/:path*', destination: '/:path*' },
{ source: '/uxcore_/:path*', destination: '/:path*' },
];
},
async headers() {
const isDev = process.env.NODE_ENV !== 'production';
const scriptSrc = [
"'self'",
"'unsafe-inline'",
// Next.js dev mode (Fast Refresh) requires eval.
isDev ? "'unsafe-eval'" : '',
'https://analytics.ahrefs.com',
'https://www.googletagmanager.com',
'https://www.google-analytics.com',
'https://cdn.mxpnl.com',
]
.filter(Boolean)
.join(' ');
const connectSrc = [
"'self'",
// Next.js dev HMR uses ws:// to localhost.
isDev ? 'ws:' : '',
'https://*.keepsimple.io',
'https://metrics.administration.ae',
'https://api.mixpanel.com',
'https://api-js.mixpanel.com',
'https://www.google-analytics.com',
'https://*.analytics.google.com',
'https://stats.g.doubleclick.net',
// Google Ads conversion: modern endpoint www.google.com/ccm/collect.
'https://www.google.com',
]
.filter(Boolean)
.join(' ');
return [
{
source: '/:path*',
headers: [
{
key: 'Strict-Transport-Security',
value: 'max-age=63072000; includeSubDomains; preload',
},
{ key: 'X-Content-Type-Options', value: 'nosniff' },
{ key: 'Referrer-Policy', value: 'strict-origin-when-cross-origin' },
{ key: 'X-Frame-Options', value: 'DENY' },
{
key: 'Permissions-Policy',
value: 'camera=(), microphone=(), geolocation=()',
},
{
key: 'Content-Security-Policy',
value: [
"default-src 'self'",
`script-src ${scriptSrc}`,
"style-src 'self' 'unsafe-inline'",
"img-src 'self' data: blob: https://lh3.googleusercontent.com https://cdn.discordapp.com https://strapi.keepsimple.io https://staging-strapi.keepsimple.io https://www.google-analytics.com https://flagcdn.com https://www.google.com",
"font-src 'self' data:",
`connect-src ${connectSrc}`,
"frame-ancestors 'none'",
"base-uri 'self'",
"form-action 'self'",
].join('; '),
},
],
},
];
},
env: {
NEXTAUTH_URL: process.env.NEXTAUTH_URL,
},
compiler: {
removeConsole: process.env.NODE_ENV === 'prod',
},
sassOptions: {
includePaths: [path.join(__dirname, 'src/styles')],
// Library SCSS modules rely on placeholder selectors (e.g. %text-base)
// that the original app injected globally. Scope that injection to the
// migrated library files only so keepsimple's own SCSS stays untouched.
additionalData: (content, loaderContext) => {
const resourcePath = (loaderContext && loaderContext.resourcePath) || '';
const isLibraryModule =
/[\\/]src[\\/](components|layouts|pages)[\\/]library[\\/]/.test(
resourcePath,
);
if (isLibraryModule) {
return `@use "library/styles.scss" as *;\n${content}`;
}
return content;
},
},
eslint: {
ignoreDuringBuilds: true,
},
images: {
domains: [
'lh3.googleusercontent.com',
'cdn.discordapp.com',
'strapi.keepsimple.io',
'staging-strapi.keepsimple.io',
],
deviceSizes: [480, 640, 750, 828, 1080, 1200, 1920, 2048, 3840],
},
webpack(config) {
config.module.rules.push({
test: /\.svg$/i,
issuer: /\.[jt]sx?$/,
use: [
{
loader: '@svgr/webpack',
options: {
// SVGO's preset-default strips viewBox, which breaks icons rendered
// at a smaller width/height than their intrinsic size (e.g. a 44x44
// icon shown at 14px clips to its top-left corner instead of
// scaling). Keep the viewBox so downscaled icons render fully.
svgoConfig: {
plugins: [
{
name: 'preset-default',
params: { overrides: { removeViewBox: false } },
},
// preset-default's cleanupIds minifies internal ids to short
// strings (a, b, c…) per file. SVGR inlines every icon into the
// same DOM, so icons that reference their own clipPath/filter/
// gradient via url(#id) (book, video, their shadows, delete,
// edit) end up with colliding ids — url(#a) resolves to whichever
// #a renders first, pointing at the wrong def and rendering blank.
// prefixIds namespaces each file's ids by filename so they stay
// unique across icons.
'prefixIds',
],
},
},
},
],
});
return config;
},
productionBrowserSourceMaps: true,
});
function loadEnv() {
const envFile = `.env.${process.env.APP_ENV || 'local'}`;
const envPath = path.join(__dirname, envFile);
if (existsSync(envPath)) {
dotenv.config({ path: envPath });
} else {
console.error(`Env file not found: ${envPath}`);
}
return {};
}