multisite/next.config.ts
2026-06-03 13:05:26 +08:00

59 lines
1.7 KiB
TypeScript

import { withPayload } from '@payloadcms/next/withPayload'
import type { NextConfig } from 'next'
import path from 'path'
import { fileURLToPath } from 'url'
const __filename = fileURLToPath(import.meta.url)
const dirname = path.dirname(__filename)
import { redirects } from './redirects'
const NEXT_PUBLIC_SERVER_URL = process.env.NEXT_PUBLIC_SERVER_URL || 'http://localhost:3002'
const S3_BUCKET_URL = process.env.NEXT_PUBLIC_S3_URL || ''
const nextConfig: NextConfig = {
output: 'standalone',
sassOptions: {
loadPaths: ['./node_modules/@payloadcms/ui/dist/scss/'],
},
images: {
localPatterns: [
{
pathname: '/api/media/file/**',
},
],
qualities: [25, 50, 75, 100],
remotePatterns: [
...[NEXT_PUBLIC_SERVER_URL, S3_BUCKET_URL].filter(Boolean).map((item) => {
const url = new URL(item)
return {
hostname: url.hostname,
protocol: url.protocol.replace(':', '') as 'http' | 'https',
pathname: '/**',
}
}),
],
},
webpack: (webpackConfig) => {
webpackConfig.resolve.extensionAlias = {
'.cjs': ['.cts', '.cjs'],
'.js': ['.ts', '.tsx', '.js', '.jsx'],
'.mjs': ['.mts', '.mjs'],
}
const replaceHash = (val: unknown) =>
typeof val === 'string' ? val.replace('[chunkhash]', '[contenthash]') : val
webpackConfig.output.filename = replaceHash(webpackConfig.output.filename)
webpackConfig.output.chunkFilename = replaceHash(webpackConfig.output.chunkFilename)
return webpackConfig
},
reactStrictMode: true,
redirects,
turbopack: {
root: path.resolve(dirname),
},
}
export default withPayload(nextConfig, { devBundleServerPackages: false })