Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
89 changes: 46 additions & 43 deletions next.config.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -12,54 +12,57 @@ const withBundleAnalyzer = bundleAnalyzer({
})

const config = withBundleAnalyzer(
withPayload({
eslint: {
ignoreDuringBuilds: true,
},
typescript: {
ignoreBuildErrors: true,
},
experimental: {
fullySpecified: true,
serverActions: {
bodySizeLimit: '5mb',
withPayload(
{
eslint: {
ignoreDuringBuilds: true,
},
},
env: {
PAYLOAD_CORE_DEV: 'true',
ROOT_DIR: path.resolve(dirname),
// @todo remove in 4.0 - will behave like this by default in 4.0
PAYLOAD_DO_NOT_SANITIZE_LOCALIZED_PROPERTY: 'true',
},
async redirects() {
return [
{
destination: '/admin',
permanent: false,
source: '/',
typescript: {
ignoreBuildErrors: true,
},
experimental: {
fullySpecified: true,
serverActions: {
bodySizeLimit: '5mb',
},
]
},
images: {
domains: ['localhost'],
},
webpack: (webpackConfig) => {
webpackConfig.resolve.extensionAlias = {
'.cjs': ['.cts', '.cjs'],
'.js': ['.ts', '.tsx', '.js', '.jsx'],
'.mjs': ['.mts', '.mjs'],
}
},
env: {
PAYLOAD_CORE_DEV: 'true',
ROOT_DIR: path.resolve(dirname),
// @todo remove in 4.0 - will behave like this by default in 4.0
PAYLOAD_DO_NOT_SANITIZE_LOCALIZED_PROPERTY: 'true',
},
async redirects() {
return [
{
destination: '/admin',
permanent: false,
source: '/',
},
]
},
images: {
domains: ['localhost'],
},
webpack: (webpackConfig) => {
webpackConfig.resolve.extensionAlias = {
'.cjs': ['.cts', '.cjs'],
'.js': ['.ts', '.tsx', '.js', '.jsx'],
'.mjs': ['.mts', '.mjs'],
}

// Ignore sentry warnings when not wrapped with withSentryConfig
webpackConfig.ignoreWarnings = [
...(webpackConfig.ignoreWarnings ?? []),
{ file: /esm\/platform\/node\/instrumentation.js/ },
{ module: /esm\/platform\/node\/instrumentation.js/ },
]
// Ignore sentry warnings when not wrapped with withSentryConfig
webpackConfig.ignoreWarnings = [
...(webpackConfig.ignoreWarnings ?? []),
{ file: /esm\/platform\/node\/instrumentation.js/ },
{ module: /esm\/platform\/node\/instrumentation.js/ },
]

return webpackConfig
return webpackConfig
},
},
}),
{ devBundleServerPackages: false },
),
)

export default process.env.NEXT_PUBLIC_SENTRY_DSN
Expand Down
30 changes: 29 additions & 1 deletion packages/next/src/withPayload.js
Original file line number Diff line number Diff line change
@@ -1,9 +1,11 @@
/**
* @param {import('next').NextConfig} nextConfig
* @param {Object} [options] - Optional configuration options
* @param {boolean} [options.devBundleServerPackages] - Whether to bundle server packages in development mode. @default true
*
* @returns {import('next').NextConfig}
* */
export const withPayload = (nextConfig = {}) => {
export const withPayload = (nextConfig = {}, options = {}) => {
const env = nextConfig?.env || {}

if (nextConfig.experimental?.staleTimes?.dynamic) {
Expand Down Expand Up @@ -99,6 +101,32 @@ export const withPayload = (nextConfig = {}) => {
'libsql',
'pino-pretty',
'graphql',
// Do not bundle server-only packages during dev to improve compile speed
...(process.env.npm_lifecycle_event === 'dev' && options.devBundleServerPackages === false
? [
'payload',
'@payloadcms/db-mongodb',
'@payloadcms/db-postgres',
'@payloadcms/db-sqlite',
'@payloadcms/db-vercel-postgres',
'@payloadcms/drizzle',
'@payloadcms/email-nodemailer',
'@payloadcms/email-resend',
'@payloadcms/graphql',
'@payloadcms/payload-cloud',
'@payloadcms/plugin-cloud-storage',
'@payloadcms/plugin-redirects',
'@payloadcms/plugin-sentry',
'@payloadcms/plugin-stripe',
// TODO: Add the following packages, excluding their /client subpath exports, once Next.js supports it
// @payloadcms/richtext-lexical
//'@payloadcms/storage-azure',
//'@payloadcms/storage-gcs',
//'@payloadcms/storage-s3',
//'@payloadcms/storage-uploadthing',
//'@payloadcms/storage-vercel-blob',
]
: []),
],
webpack: (webpackConfig, webpackOptions) => {
const incomingWebpackConfig =
Expand Down
6 changes: 3 additions & 3 deletions packages/payload-cloud/src/utilities/refreshSession.ts
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
import { CognitoIdentityClient } from '@aws-sdk/client-cognito-identity'
import * as AWS from '@aws-sdk/client-s3'
import { S3 } from '@aws-sdk/client-s3'
import { fromCognitoIdentityPool } from '@aws-sdk/credential-providers'

import { authAsCognitoUser } from './authAsCognitoUser.js'

export type GetStorageClient = () => Promise<{
identityID: string
storageClient: AWS.S3
storageClient: S3
}>

export const refreshSession = async () => {
Expand All @@ -33,7 +33,7 @@ export const refreshSession = async () => {
// @ts-expect-error - Incorrect AWS types
const identityID = credentials.identityId

const storageClient = new AWS.S3({
const storageClient = new S3({
credentials,
region: process.env.PAYLOAD_CLOUD_BUCKET_REGION,
})
Expand Down
2 changes: 1 addition & 1 deletion templates/_template/next.config.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -5,4 +5,4 @@ const nextConfig = {
// Your Next.js config here
}

export default withPayload(nextConfig)
export default withPayload(nextConfig, { devBundleServerPackages: false })
2 changes: 1 addition & 1 deletion templates/blank/next.config.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -5,4 +5,4 @@ const nextConfig = {
// Your Next.js config here
}

export default withPayload(nextConfig)
export default withPayload(nextConfig, { devBundleServerPackages: false })
2 changes: 1 addition & 1 deletion templates/plugin/dev/next.config.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -18,4 +18,4 @@ const nextConfig = {
// transpilePackages: ['../src'],
}

export default withPayload(nextConfig)
export default withPayload(nextConfig, { devBundleServerPackages: false })
2 changes: 1 addition & 1 deletion templates/website/next.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -24,4 +24,4 @@ const nextConfig = {
redirects,
}

export default withPayload(nextConfig)
export default withPayload(nextConfig, { devBundleServerPackages: false })
2 changes: 1 addition & 1 deletion templates/with-payload-cloud/next.config.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -5,4 +5,4 @@ const nextConfig = {
// Your Next.js config here
}

export default withPayload(nextConfig)
export default withPayload(nextConfig, { devBundleServerPackages: false })
2 changes: 1 addition & 1 deletion templates/with-postgres/next.config.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -5,4 +5,4 @@ const nextConfig = {
// Your Next.js config here
}

export default withPayload(nextConfig)
export default withPayload(nextConfig, { devBundleServerPackages: false })
2 changes: 1 addition & 1 deletion templates/with-vercel-mongodb/next.config.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -5,4 +5,4 @@ const nextConfig = {
// Your Next.js config here
}

export default withPayload(nextConfig)
export default withPayload(nextConfig, { devBundleServerPackages: false })
2 changes: 1 addition & 1 deletion templates/with-vercel-postgres/next.config.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -5,4 +5,4 @@ const nextConfig = {
// Your Next.js config here
}

export default withPayload(nextConfig)
export default withPayload(nextConfig, { devBundleServerPackages: false })
2 changes: 1 addition & 1 deletion templates/with-vercel-website/next.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -24,4 +24,4 @@ const nextConfig = {
redirects,
}

export default withPayload(nextConfig)
export default withPayload(nextConfig, { devBundleServerPackages: false })
77 changes: 40 additions & 37 deletions test/next.config.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -12,45 +12,48 @@ const withBundleAnalyzer = bundleAnalyzer({
})

export default withBundleAnalyzer(
withPayload({
eslint: {
ignoreDuringBuilds: true,
},
typescript: {
ignoreBuildErrors: true,
},
experimental: {
fullySpecified: true,
serverActions: {
bodySizeLimit: '5mb',
withPayload(
{
eslint: {
ignoreDuringBuilds: true,
},
},
env: {
PAYLOAD_CORE_DEV: 'true',
ROOT_DIR: path.resolve(dirname),
// @todo remove in 4.0 - will behave like this by default in 4.0
PAYLOAD_DO_NOT_SANITIZE_LOCALIZED_PROPERTY: 'true',
},
async redirects() {
return [
{
destination: '/admin',
permanent: true,
source: '/',
typescript: {
ignoreBuildErrors: true,
},
experimental: {
fullySpecified: true,
serverActions: {
bodySizeLimit: '5mb',
},
]
},
images: {
domains: ['localhost'],
},
webpack: (webpackConfig) => {
webpackConfig.resolve.extensionAlias = {
'.cjs': ['.cts', '.cjs'],
'.js': ['.ts', '.tsx', '.js', '.jsx'],
'.mjs': ['.mts', '.mjs'],
}
},
env: {
PAYLOAD_CORE_DEV: 'true',
ROOT_DIR: path.resolve(dirname),
// @todo remove in 4.0 - will behave like this by default in 4.0
PAYLOAD_DO_NOT_SANITIZE_LOCALIZED_PROPERTY: 'true',
},
async redirects() {
return [
{
destination: '/admin',
permanent: true,
source: '/',
},
]
},
images: {
domains: ['localhost'],
},
webpack: (webpackConfig) => {
webpackConfig.resolve.extensionAlias = {
'.cjs': ['.cts', '.cjs'],
'.js': ['.ts', '.tsx', '.js', '.jsx'],
'.mjs': ['.mts', '.mjs'],
}

return webpackConfig
return webpackConfig
},
},
}),
{ devBundleServerPackages: false },
),
)