-
Notifications
You must be signed in to change notification settings - Fork 13
Expand file tree
/
Copy pathnext.config.ts
More file actions
93 lines (84 loc) · 2.35 KB
/
Copy pathnext.config.ts
File metadata and controls
93 lines (84 loc) · 2.35 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
import fs from "fs";
import path from "path";
import { NextConfig } from "next";
const packageRoot = process.cwd();
const localNextPackage = path.join(
packageRoot,
"node_modules",
"next",
"package.json"
);
if (!fs.existsSync(localNextPackage)) {
console.error(
`${localNextPackage} not found; is Next installed in the local \`node_modules\`?`
);
process.exit(1);
}
const watchOptions =
process.env.ENVIRONMENT === "dev_docker"
? {
watchOptions: {
// Turbopack-specific polling for watch options (might be needed for e.g. Docker environments if host filesystem does not reliably notify of changes)
// TODO: check if this is equivalent to WATCHPACK_POLLING environment variable
pollIntervalMs: 1000, // Check for changes every 1 second
},
}
: {};
const nextConfig: NextConfig = {
...watchOptions,
reactCompiler: true,
productionBrowserSourceMaps: true,
experimental: {
optimizePackageImports: ["@chakra-ui/react"],
},
compiler: {
emotion: true,
},
rewrites: async () => {
const env = process.env.ENVIRONMENT;
let backendHost;
if (env === "local") {
backendHost = "http://127.0.0.1:8000"; // Local development backend
} else if (env === "dev_docker") {
backendHost = "http://backend:8000"; // In docker, the service name is used as the hostname
} else {
backendHost = ""; // In preview and production, the backend is served from the same origin
}
const rewrites = [];
// Only add API rewrite if backendHost is defined. Docs and openapi.json are available for devs only.
if (backendHost) {
rewrites.push(
{
source: "/api/:path*",
destination: `${backendHost}/api/:path*`,
},
{
source: "/docs",
destination: `${backendHost}/docs`,
},
{
source: "/openapi.json",
destination: `${backendHost}/openapi.json`,
}
);
}
return rewrites;
},
turbopack: {
root: packageRoot,
rules: {
"*.svg": {
loaders: [
{
loader: "@svgr/webpack",
options: {
icon: true, // This is your desired option
},
},
],
as: "*.js", // Important to tell Turbopack to treat as JS module
},
},
},
};
export default nextConfig;