ChatGPT-Next-Web/next.config.mjs
sijinhui a83d79a9f4 Merge remote-tracking branch 'upstream/main' into dev
# Conflicts:
#	app/api/auth.ts
#	app/client/platforms/openai.ts
#	app/components/settings.tsx
#	app/config/server.ts
#	app/constant.ts
#	app/locales/pt.ts
#	app/locales/sk.ts
#	app/locales/tw.ts
#	app/store/chat.ts
2024-04-09 10:39:16 +08:00

159 lines
4.1 KiB
JavaScript
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

import webpack from "webpack";
// import CssMinimizerPlugin from "css-minimizer-webpack-plugin";
const mode = process.env.BUILD_MODE ?? "standalone";
console.log("[Next] build mode", mode);
const disableChunk = !!process.env.DISABLE_CHUNK || mode === "export";
console.log("[Next] build with chunk: ", disableChunk);
/** @type {import('next').NextConfig} */
// const isProd = process.env.NODE_ENV === 'production'
// 为了修复tiktoken的插件问题
const nextConfig = {
// transpilePackages: ['tiktoken'],
webpack(config) {
config.module.rules.push({
test: /\.svg$/,
use: ["@svgr/webpack"],
});
if (disableChunk) {
config.plugins.push(
new webpack.optimize.LimitChunkCountPlugin({ maxChunks: 1 }),
)
}
// turn off static file serving of WASM files
// we need to let Webpack handle WASM import
// config.module.rules
// .find((i) => "oneOf" in i)
// .oneOf.find((i) => i.type === "asset/resource")
// .exclude.push(/\.wasm$/);
// config.plugins.push(
// new CopyPlugin({
// patterns: [
// {
// from: ".//node_modules/tiktoken/,
// to: "",
// }
// ]
// })
// )
config.optimization.minimize = true
config.optimization.splitChunks = {
minSize: 1024 * 300
}
// console.log('=======', config.optimization)
config.resolve.fallback = {
child_process: false,
};
// tiktoken
config.experiments = {
asyncWebAssembly: true,
layers: true,
};
return config;
},
output: mode,
// 不影响publichttps://www.nextjs.cn/docs/api-reference/next.config.js/cdn-support-with-asset-prefix
// assetPrefix: isProd ? "https://cos.xiaosi.cc" : "",
images: {
unoptimized: mode === "export",
// domains: ["cos.xiaosi.cc"],
remotePatterns: [
{ hostname: "**.xiaosi.cc" },
{ hostname: "public.blob.vercel-storage.com" },
{ hostname: "res.cloudinary.com" },
{ hostname: "abs.twimg.com" },
{ hostname: "pbs.twimg.com" },
{ hostname: "avatar.vercel.sh" },
{ hostname: "avatars.githubusercontent.com" },
{ hostname: "www.google.com" },
{ hostname: "flag.vercel.app" },
{ hostname: "illustrations.popsy.co" },
]
},
experimental: {
forceSwcTransforms: true,
},
swcMinify: true,
};
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",
},
];
const IndexHeaders = [
{ key: "Cache-Control", value: "public, max-age=86400"}
]
const ForceCacheHeaders = [
{ key: "Cache-Control", value: "max-age=2592000, s-maxage=86400"}
]
if (mode !== "export") {
// nextConfig.headers = async () => {
// return [
// {
// source: "/:path*\\.(png|ico|txt|css|js|json|webmanifest)",
// headers: ForceCacheHeaders,
// },
// {
// source: "/api/:path*",
// headers: CorsHeaders,
// },
// ];
// };
nextConfig.rewrites = async () => {
const ret = [
// adjust for previous version directly using "/api/proxy/" as proxy base route
{
source: "/api/proxy/v1/:path*",
destination: "https://api.openai.com/v1/:path*",
},
{
source: "/api/proxy/google/:path*",
destination: "https://generativelanguage.googleapis.com/:path*",
},
{
source: "/api/proxy/openai/:path*",
destination: "https://api.openai.com/:path*",
},
{
source: "/api/proxy/anthropic/:path*",
destination: "https://api.anthropic.com/:path*",
},
{
source: "/google-fonts/:path*",
destination: "https://fonts.googleapis.com/:path*",
},
{
source: "/sharegpt",
destination: "https://sharegpt.com/api/conversations",
},
];
return {
beforeFiles: ret,
};
};
}
export default nextConfig;