2023-06-29 23:28:29 +08:00
|
|
|
import webpack from "webpack";
|
|
|
|
|
2023-06-07 23:47:21 +08:00
|
|
|
const mode = process.env.BUILD_MODE ?? "standalone";
|
|
|
|
console.log("[Next] build mode", mode);
|
2023-03-13 03:06:21 +08:00
|
|
|
|
2023-06-29 23:28:29 +08:00
|
|
|
const disableChunk = !!process.env.DISABLE_CHUNK || mode === "export";
|
|
|
|
console.log("[Next] build with chunk: ", !disableChunk);
|
|
|
|
|
2023-06-07 23:47:21 +08:00
|
|
|
/** @type {import('next').NextConfig} */
|
2023-03-13 03:21:48 +08:00
|
|
|
const nextConfig = {
|
2023-06-07 23:47:21 +08:00
|
|
|
webpack(config) {
|
|
|
|
config.module.rules.push({
|
|
|
|
test: /\.svg$/,
|
|
|
|
use: ["@svgr/webpack"],
|
|
|
|
});
|
|
|
|
|
2023-06-29 23:28:29 +08:00
|
|
|
if (disableChunk) {
|
|
|
|
config.plugins.push(
|
|
|
|
new webpack.optimize.LimitChunkCountPlugin({ maxChunks: 1 }),
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
2023-07-09 22:18:48 +08:00
|
|
|
config.resolve.fallback = {
|
|
|
|
child_process: false,
|
|
|
|
};
|
|
|
|
|
2023-06-07 23:47:21 +08:00
|
|
|
return config;
|
|
|
|
},
|
|
|
|
output: mode,
|
2023-06-15 23:20:14 +08:00
|
|
|
images: {
|
|
|
|
unoptimized: mode === "export",
|
|
|
|
},
|
2023-07-16 16:32:22 +08:00
|
|
|
experimental: {
|
|
|
|
forceSwcTransforms: true,
|
|
|
|
},
|
2023-06-07 23:47:21 +08:00
|
|
|
};
|
|
|
|
|
2023-09-13 02:51:02 +08:00
|
|
|
const CorsHeaders = [
|
|
|
|
{ key: "Access-Control-Allow-Credentials", value: "true" },
|
|
|
|
{ key: "Access-Control-Allow-Origin", value: "*" },
|
|
|
|
{
|
|
|
|
key: "Access-Control-Allow-Methods",
|
|
|
|
value: "*",
|
|
|
|
},
|
|
|
|
{
|
|
|
|
key: "Access-Control-Allow-Headers",
|
|
|
|
value: "*",
|
|
|
|
},
|
|
|
|
{
|
|
|
|
key: "Access-Control-Max-Age",
|
|
|
|
value: "86400",
|
|
|
|
},
|
|
|
|
];
|
|
|
|
|
2023-06-07 23:47:21 +08:00
|
|
|
if (mode !== "export") {
|
2023-06-14 00:37:42 +08:00
|
|
|
nextConfig.headers = async () => {
|
|
|
|
return [
|
|
|
|
{
|
2023-06-15 00:28:47 +08:00
|
|
|
source: "/api/:path*",
|
2023-09-13 02:51:02 +08:00
|
|
|
headers: CorsHeaders,
|
2023-06-14 00:37:42 +08:00
|
|
|
},
|
|
|
|
];
|
|
|
|
};
|
|
|
|
|
2023-06-07 23:47:21 +08:00
|
|
|
nextConfig.rewrites = async () => {
|
2023-05-09 00:39:00 +08:00
|
|
|
const ret = [
|
|
|
|
{
|
|
|
|
source: "/api/proxy/:path*",
|
|
|
|
destination: "https://api.openai.com/:path*",
|
|
|
|
},
|
2023-05-14 23:25:22 +08:00
|
|
|
{
|
|
|
|
source: "/google-fonts/:path*",
|
|
|
|
destination: "https://fonts.googleapis.com/:path*",
|
|
|
|
},
|
2023-05-25 01:04:37 +08:00
|
|
|
{
|
|
|
|
source: "/sharegpt",
|
|
|
|
destination: "https://sharegpt.com/api/conversations",
|
|
|
|
},
|
2023-05-09 00:39:00 +08:00
|
|
|
];
|
2023-05-03 23:49:33 +08:00
|
|
|
|
2023-05-04 22:18:03 +08:00
|
|
|
return {
|
2023-05-05 22:49:41 +08:00
|
|
|
beforeFiles: ret,
|
2023-05-04 22:18:03 +08:00
|
|
|
};
|
2023-06-07 23:47:21 +08:00
|
|
|
};
|
|
|
|
}
|
2023-03-10 01:01:40 +08:00
|
|
|
|
2023-05-03 23:08:37 +08:00
|
|
|
export default nextConfig;
|