forked from bigcommerce/catalyst
-
Notifications
You must be signed in to change notification settings - Fork 0
/
next.config.ts
78 lines (67 loc) · 2.01 KB
/
next.config.ts
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
import bundleAnalyzer from '@next/bundle-analyzer';
import type { NextConfig } from 'next';
import createNextIntlPlugin from 'next-intl/plugin';
import { writeBuildConfig } from './build-config/writer';
import { client } from './client';
import { graphql } from './client/graphql';
import { cspHeader } from './lib/content-security-policy';
const withNextIntl = createNextIntlPlugin();
const LocaleQuery = graphql(`
query LocaleQuery {
site {
settings {
locales {
code
isDefault
}
}
}
}
`);
export default async (): Promise<NextConfig> => {
let nextConfig: NextConfig = {
reactStrictMode: true,
experimental: {
optimizePackageImports: ['@icons-pack/react-simple-icons'],
},
typescript: {
ignoreBuildErrors: !!process.env.CI,
},
eslint: {
ignoreDuringBuilds: !!process.env.CI,
dirs: ['app', 'client', 'components', 'lib', 'middlewares'],
},
// default URL generation in BigCommerce uses trailing slash
trailingSlash: process.env.TRAILING_SLASH !== 'false',
// eslint-disable-next-line @typescript-eslint/require-await
async headers() {
return [
{
source: '/(.*)',
headers: [
{
key: 'Content-Security-Policy',
value: cspHeader.replace(/\n/g, ''),
},
{
key: 'Link',
value: `<https://${process.env.BIGCOMMERCE_CDN_HOSTNAME ?? 'cdn11.bigcommerce.com'}>; rel=preconnect`,
},
],
},
];
},
};
// Apply withNextIntl to the config
nextConfig = withNextIntl(nextConfig);
if (process.env.ANALYZE === 'true') {
const withBundleAnalyzer = bundleAnalyzer();
nextConfig = withBundleAnalyzer(nextConfig);
}
await writeLocaleToBuildConfig();
return nextConfig;
};
async function writeLocaleToBuildConfig() {
const { data } = await client.fetch({ document: LocaleQuery });
await writeBuildConfig({ locales: data.site.settings?.locales });
}