-
Notifications
You must be signed in to change notification settings - Fork 114
Expand file tree
/
Copy pathnext.config.js
More file actions
231 lines (205 loc) · 7.28 KB
/
next.config.js
File metadata and controls
231 lines (205 loc) · 7.28 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
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
import bundleAnalyzer from "@next/bundle-analyzer";
import { withSentryConfig } from "@sentry/nextjs";
import { config } from "dotenv-flow";
import webpack from "webpack";
// eslint-disable-next-line import/extensions
import { buildStamp } from "./buildstamp.js";
const { DefinePlugin } = webpack;
const withBundleAnalyzer = bundleAnalyzer({
enabled: process.env.ANALYZE === "true",
});
config({ silent: true, path: "../.." });
/**
* @type {import('@sentry/nextjs').SentryBuildOptions}
*/
const sentryWebpackPluginOptions = {
disableLogger: true,
reactComponentAnnotation: {
enabled: true,
},
release: {
name: buildStamp,
},
silent: true,
widenClientFileUpload: true,
// For all available options, see:
// https://github.com/getsentry/sentry-webpack-plugin#options.
};
// Insert other public env variables here. We have to add the `NEXT_PUBLIC` prefix for next to find them.
// They then get converted into variables with the right name in `frontend/src/lib/public-env.ts`
// NOTE THAT any environment variable which is _missing_ will be converted to the string 'undefined' if no fallback is set
// Show the worker cost in the UI. Always enabled for admins
process.env.NEXT_PUBLIC_SHOW_WORKER_COST =
process.env.SHOW_WORKER_COST ?? "false";
// This allows the frontend to generate the graph type IDs in the browser
process.env.NEXT_PUBLIC_FRONTEND_URL = process.env.FRONTEND_URL;
// The API origin
process.env.NEXT_PUBLIC_API_ORIGIN =
process.env.API_ORIGIN ?? "http://localhost:5001";
process.env.NEXT_PUBLIC_SENTRY_DSN = process.env.SENTRY_DSN ?? "";
process.env.NEXT_PUBLIC_SENTRY_REPLAY_SESSION_SAMPLE_RATE =
process.env.SENTRY_REPLAY_SESSION_SAMPLE_RATE ?? "1";
process.env.NEXT_PUBLIC_NOTIFICATION_POLL_INTERVAL =
process.env.NOTIFICATION_POLL_INTERVAL ?? "";
process.env.NEXT_PUBLIC_SELF_HOSTED_HASH = process.env.SELF_HOSTED_HASH ?? "";
process.env.NEXT_PUBLIC_GOOGLE_OAUTH_CLIENT_ID =
process.env.GOOGLE_OAUTH_CLIENT_ID ?? "";
const apiUrl = process.env.NEXT_PUBLIC_API_ORIGIN ?? "http://localhost:5001";
const apiDomain = new URL(apiUrl).hostname;
/**
* @todo: import the page `entityTypeId` from `@local/hash-isomorphic-utils/ontology-types`
* when the `next.config.js` supports imports from modules
*/
const pageEntityTypeBaseUrl = "https://hash.ai/@h/types/entity-type/page/";
/**
* @todo make plugin definition cleaner - some ideas in https://github.com/cyrilwanner/next-compose-plugins/issues/59
* next-compose plugins itself is unmaintained and leads to 'invalid config property' warnings if used
*/
// eslint-disable-next-line import/no-default-export
export default withSentryConfig(
withBundleAnalyzer(
/** @type {import('next').NextConfig} */
{
async rewrites() {
return [
{
source: "/pages",
destination: `/entities?entityTypeIdOrBaseUrl=${pageEntityTypeBaseUrl}`,
},
{
source: "/@:shortname/types",
destination: "/@/:shortname?tab=Types",
},
{
source: "/@:shortname/:path*",
destination: "/@/:shortname/:path*",
},
];
},
images: {
domains: [apiDomain],
},
async redirects() {
return [
{
source: "/settings/organizations/:shortname(^(?!new)$)",
destination: "/settings/organizations/:shortname/general",
permanent: true,
},
{
source: "/login",
destination: "/signin",
permanent: true,
},
{
source: "/inbox",
destination: "/notifications",
permanent: false,
},
];
},
async headers() {
return [
{
/**
* allow fetching types as JSON from anywhere
* see /src/middleware.page.ts for middleware which serves the JSON
*/
source: "/:shortname/types/:path*",
has: [
{
type: "header",
key: "accept",
value: "(.*application/json.*)",
},
],
headers: [
{
key: "access-control-allow-origin",
value: "*",
},
],
},
];
},
pageExtensions: ["page.tsx", "page.ts", "page.jsx", "page.jsx", "api.ts"],
// We call linters in GitHub Actions for all pull requests. By not linting
// again during `next build`, we save CI minutes and unlock more feedback.
// Thus, we can get Playwright test results and Preview releases for WIP PRs.
eslint: { ignoreDuringBuilds: true },
typescript: { ignoreBuildErrors: true },
transpilePackages: [
"@blockprotocol/service",
"@blockprotocol/core",
"@blockprotocol/graph",
"@blockprotocol/hook",
"@blockprotocol/type-system",
"@emotion/server",
"@hashintel/block-design-system",
"@hashintel/design-system",
"@hashintel/petrinaut",
"@hashintel/ds-components",
"@hashintel/ds-helpers",
"@hashintel/type-editor",
"echarts",
"zrender",
"@hashintel/query-editor",
"@local/advanced-types",
"@local/hash-graph-client",
"@local/hash-isomorphic-utils",
"react-syntax-highlighter",
"@tldraw/polyfills",
"@tldraw/tldraw",
"@tldraw/tlschema",
"@tldraw/ui",
],
// These are introduced in the monorepo by the Temporal packages, and despite them not being part of the
// frontend dependency tree, they are not shaken and are included in the generated lambdas
// https://github.com/orgs/vercel/discussions/103#discussioncomment-5427097
outputFileTracingExcludes: {
"*": [
"node_modules/@swc/core-linux-x64-gnu",
"node_modules/@swc/core-linux-x64-musl",
"node_modules/@esbuild/linux-x64",
],
},
webpack: (webpackConfig, { isServer }) => {
webpackConfig.module.rules.push({
test: /\.svg$/,
use: ["@svgr/webpack"],
});
// eslint-disable-next-line no-param-reassign
webpackConfig.experiments.asyncWebAssembly = true;
if (!isServer) {
// eslint-disable-next-line no-param-reassign
webpackConfig.output.publicPath = `/_next/`;
} else {
// eslint-disable-next-line no-param-reassign
webpackConfig.output.publicPath = `./`;
}
// eslint-disable-next-line no-param-reassign
webpackConfig.output.assetModuleFilename = `static/[hash][ext]`;
webpackConfig.module.rules.push({
test: /\.(wasm)$/,
type: "asset/resource",
});
// eslint-disable-next-line no-param-reassign
webpackConfig.resolve.extensionAlias = {
".js": [".ts", ".tsx", ".jsx", ".js"],
".mjs": [".mts", ".mjs"],
".cjs": [".cts", ".cjs"],
};
// eslint-disable-next-line no-param-reassign
webpackConfig.resolve.alias.canvas = false;
webpackConfig.plugins.push(
new DefinePlugin({
__SENTRY_DEBUG__: false,
__SENTRY_TRACING__: false,
}),
);
return webpackConfig;
},
},
),
sentryWebpackPluginOptions,
);