99 lines
2.8 KiB
JavaScript
99 lines
2.8 KiB
JavaScript
const path = require('path');
|
||
|
||
/** @type {import('next').NextConfig} */
|
||
const nextConfig = {
|
||
reactStrictMode: true,
|
||
swcMinify: true,
|
||
experimental: {
|
||
serverComponentsExternalPackages: ['axios'],
|
||
},
|
||
images: {
|
||
domains: [
|
||
'localhost',
|
||
'ckbapi.quwanzhi.com',
|
||
'blob.v0.dev',
|
||
'hebbkx1anhila5yf.public.blob.vercel-storage.com'
|
||
],
|
||
formats: ['image/webp', 'image/avif'],
|
||
unoptimized: true,
|
||
},
|
||
env: {
|
||
CUSTOM_KEY: process.env.CUSTOM_KEY,
|
||
},
|
||
async redirects() {
|
||
return [
|
||
{
|
||
source: '/scenarios/new',
|
||
destination: '/scenarios/new/basic',
|
||
permanent: false,
|
||
},
|
||
];
|
||
},
|
||
async rewrites() {
|
||
const apiBase = process.env.NEXT_PUBLIC_API_BASE_URL;
|
||
if (!apiBase) {
|
||
console.warn('环境变量 NEXT_PUBLIC_API_BASE_URL 未设置,rewrites 不生效');
|
||
return [];
|
||
}
|
||
return [
|
||
{
|
||
source: '/api/proxy/:path*',
|
||
destination: `${apiBase}/:path*`,
|
||
},
|
||
];
|
||
},
|
||
async headers() {
|
||
return [
|
||
{
|
||
source: '/api/:path*',
|
||
headers: [
|
||
{ key: 'Access-Control-Allow-Origin', value: '*' },
|
||
{ key: 'Access-Control-Allow-Methods', value: 'GET, POST, PUT, DELETE, OPTIONS' },
|
||
{ key: 'Access-Control-Allow-Headers', value: 'Content-Type, Authorization' },
|
||
],
|
||
},
|
||
];
|
||
},
|
||
webpack: (config, { buildId, dev, isServer, defaultLoaders, webpack }) => {
|
||
config.resolve.alias = {
|
||
...config.resolve.alias,
|
||
'@': path.resolve(__dirname),
|
||
};
|
||
config.resolve.fallback = {
|
||
...config.resolve.fallback,
|
||
fs: false,
|
||
net: false,
|
||
tls: false,
|
||
};
|
||
return config;
|
||
},
|
||
output: 'standalone',
|
||
compress: true,
|
||
poweredByHeader: false,
|
||
generateEtags: true,
|
||
pageExtensions: ['ts', 'tsx', 'js', 'jsx', 'md', 'mdx'],
|
||
trailingSlash: false,
|
||
distDir: '.next',
|
||
staticPageGenerationTimeout: 60,
|
||
...(process.env.NODE_ENV === 'development' && {
|
||
onDemandEntries: {
|
||
maxInactiveAge: 25 * 1000,
|
||
pagesBufferLength: 2,
|
||
},
|
||
}),
|
||
eslint: {
|
||
ignoreDuringBuilds: true,
|
||
},
|
||
typescript: {
|
||
ignoreBuildErrors: true,
|
||
},
|
||
};
|
||
|
||
if (process.env.ANALYZE === 'true') {
|
||
const withBundleAnalyzer = require('@next/bundle-analyzer')({
|
||
enabled: true,
|
||
});
|
||
module.exports = withBundleAnalyzer(nextConfig);
|
||
} else {
|
||
module.exports = nextConfig;
|
||
}
|