-
Notifications
You must be signed in to change notification settings - Fork 4
/
next.config.js
146 lines (128 loc) · 4.28 KB
/
next.config.js
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
/* eslint-disable no-restricted-syntax */
const { secrets } = require('docker-secret');
const { mkdir } = require('node:fs/promises');
const lockfile = require('proper-lockfile');
const path = require('path');
const withBundleAnalyzer = require('@next/bundle-analyzer')({
enabled: process.env.ANALYZE === 'true',
});
const withNextIntl = require('next-intl/plugin')('./config/i18n.ts');
if (process.env.DOTENV_CONFIG_PATH) {
// Load CI environment variables defined in Ansible
require('dotenv').config({ path: process.env.DOTENV_CONFIG_PATH });
}
const sentryAuthToken =
secrets.SENTRY_AUTH_TOKEN || process.env.SENTRY_AUTH_TOKEN;
console.log(`
⚙ Kausal Watch UI
↝ Initialising app
↝ NODE_ENV: ${process.env.NODE_ENV}
↝ NEXT_PUBLIC_DEPLOYMENT_TYPE: ${process.env.NEXT_PUBLIC_DEPLOYMENT_TYPE}
↝ NEXT_PUBLIC_API_URL: ${process.env.NEXT_PUBLIC_API_URL}
`);
async function initializeThemes() {
const staticPath = path.join(__dirname, 'public', 'static');
await mkdir(staticPath, { recursive: true });
const releaseThemeLock = await lockfile.lock('public/static');
try {
const destPath = path.join(__dirname, 'public', 'static', 'themes');
let themesLinked = false;
try {
const {
generateThemeSymlinks: generateThemeSymlinksPrivate,
} = require('@kausal/themes-private/setup.cjs');
generateThemeSymlinksPrivate(destPath, { verbose: false });
themesLinked = true;
} catch (error) {
if (error.code !== 'MODULE_NOT_FOUND') {
console.error(error);
throw error;
}
}
if (!themesLinked) {
console.log('Private themes not found; using public themes');
const {
generateThemeSymlinks: generateThemeSymlinksPublic,
} = require('@kausal/themes/setup.cjs');
generateThemeSymlinksPublic(destPath, { verbose: false });
}
} finally {
await releaseThemeLock();
}
}
initializeThemes();
/**
* @type {import('next').NextConfig}
*/
let config = {
logging: {
fetches: {
fullUrl: true,
},
},
eslint: {
// Warning: This allows production builds to successfully complete even if
// your project has ESLint errors.
ignoreDuringBuilds: true,
},
typescript: {
// !! WARN !!
// Dangerously allow production builds to successfully complete even if
// your project has type errors.
// !! WARN !!
ignoreBuildErrors: true,
},
productionBrowserSourceMaps: true,
compiler: {
// Enables the styled-components SWC transform
styledComponents: true,
},
webpack(config, { webpack }) {
if (process.env.NODE_ENV !== 'development') {
// Disable Apollo Client development mode
config.plugins.push(
new webpack.DefinePlugin({
'globalThis.__DEV__': false,
})
);
}
return config;
},
};
module.exports = withNextIntl(config);
if (sentryAuthToken) {
const { withSentryConfig } = require('@sentry/nextjs');
// Injected content via Sentry wizard below
module.exports = withSentryConfig(
module.exports,
{
// For all available options, see:
// https://github.com/getsentry/sentry-webpack-plugin#options
authToken: sentryAuthToken,
// Suppresses source map uploading logs during build
silent: true,
org: 'kausal',
project: 'watch-ui',
url: 'https://sentry.kausal.tech/',
},
{
// For all available options, see:
// https://docs.sentry.io/platforms/javascript/guides/nextjs/manual-setup/
// Upload a larger set of source maps for prettier stack traces (increases build time)
widenClientFileUpload: true,
// Transpiles SDK to be compatible with IE11 (increases bundle size)
transpileClientSDK: true,
// Routes browser requests to Sentry through a Next.js rewrite to circumvent ad-blockers (increases server load)
tunnelRoute: '/monitoring',
// Hides source maps from generated client bundles
hideSourceMaps: true,
// Automatically tree-shake Sentry logger statements to reduce bundle size
disableLogger: true,
// Enables automatic instrumentation of Vercel Cron Monitors.
// See the following for more information:
// https://docs.sentry.io/product/crons/
// https://vercel.com/docs/cron-jobs
automaticVercelMonitors: true,
}
);
}