-
Notifications
You must be signed in to change notification settings - Fork 4
Expand file tree
/
Copy pathnext.config.ts
More file actions
42 lines (34 loc) · 1.24 KB
/
next.config.ts
File metadata and controls
42 lines (34 loc) · 1.24 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
import type { NextConfig } from "next";
import webpack from "webpack";
import { loadScenariosFromFile, writeScenariosToFile } from "./src/server/_loadScenarios";
import { PHASE_PRODUCTION_SERVER, PHASE_DEVELOPMENT_SERVER } from "next/dist/shared/lib/constants";
class WriteScenariosPlugin {
apply(compiler: webpack.Compiler) {
compiler.hooks.done.tap(WriteScenariosPlugin.name, writeScenariosToFile);
}
}
const getServerRuntimeConfig = (phase: string) => {
if (phase === PHASE_PRODUCTION_SERVER || phase === PHASE_DEVELOPMENT_SERVER) {
return { scenarios: loadScenariosFromFile() };
}
return {};
};
const nextConfig: NextConfig = (phase: string) => {
return {
// Disable compression to avoid memory issues
compress: false,
serverRuntimeConfig: getServerRuntimeConfig(phase),
webpack: (config: any, options: any) => {
config.optimization = {
...config.optimization,
moduleIds: "deterministic",
chunkIds: "deterministic",
};
if (!options.isServer) {
config.plugins.push(new WriteScenariosPlugin());
}
return config;
},
};
};
export default nextConfig;