perf: 50% faster compilation speed by skipping bundling of server-only packages during dev (#11594)
This PR skips bundling server-only payload packages during development, which results in 50% faster compilation speeds using turbo. Test results using our blank template (both /api and /admin): Webpack before: 11.5 Webpack now: 7.1s => 38% faster compilation speed Turbopack before: 4.1s Turbopack after: 2.1s => 50% faster compilation speed
This commit is contained in:
@@ -12,54 +12,57 @@ const withBundleAnalyzer = bundleAnalyzer({
|
|||||||
})
|
})
|
||||||
|
|
||||||
const config = withBundleAnalyzer(
|
const config = withBundleAnalyzer(
|
||||||
withPayload({
|
withPayload(
|
||||||
eslint: {
|
{
|
||||||
ignoreDuringBuilds: true,
|
eslint: {
|
||||||
},
|
ignoreDuringBuilds: true,
|
||||||
typescript: {
|
},
|
||||||
ignoreBuildErrors: true,
|
typescript: {
|
||||||
},
|
ignoreBuildErrors: true,
|
||||||
experimental: {
|
},
|
||||||
fullySpecified: true,
|
experimental: {
|
||||||
serverActions: {
|
fullySpecified: true,
|
||||||
bodySizeLimit: '5mb',
|
serverActions: {
|
||||||
|
bodySizeLimit: '5mb',
|
||||||
|
},
|
||||||
|
},
|
||||||
|
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/ },
|
||||||
|
]
|
||||||
|
|
||||||
|
return webpackConfig
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
env: {
|
{ devBundleServerPackages: false },
|
||||||
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/ },
|
|
||||||
]
|
|
||||||
|
|
||||||
return webpackConfig
|
|
||||||
},
|
|
||||||
}),
|
|
||||||
)
|
)
|
||||||
|
|
||||||
export default process.env.NEXT_PUBLIC_SENTRY_DSN
|
export default process.env.NEXT_PUBLIC_SENTRY_DSN
|
||||||
|
|||||||
@@ -1,9 +1,11 @@
|
|||||||
/**
|
/**
|
||||||
* @param {import('next').NextConfig} nextConfig
|
* @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}
|
* @returns {import('next').NextConfig}
|
||||||
* */
|
* */
|
||||||
export const withPayload = (nextConfig = {}) => {
|
export const withPayload = (nextConfig = {}, options = {}) => {
|
||||||
const env = nextConfig?.env || {}
|
const env = nextConfig?.env || {}
|
||||||
|
|
||||||
if (nextConfig.experimental?.staleTimes?.dynamic) {
|
if (nextConfig.experimental?.staleTimes?.dynamic) {
|
||||||
@@ -99,6 +101,32 @@ export const withPayload = (nextConfig = {}) => {
|
|||||||
'libsql',
|
'libsql',
|
||||||
'pino-pretty',
|
'pino-pretty',
|
||||||
'graphql',
|
'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) => {
|
webpack: (webpackConfig, webpackOptions) => {
|
||||||
const incomingWebpackConfig =
|
const incomingWebpackConfig =
|
||||||
|
|||||||
@@ -1,12 +1,12 @@
|
|||||||
import { CognitoIdentityClient } from '@aws-sdk/client-cognito-identity'
|
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 { fromCognitoIdentityPool } from '@aws-sdk/credential-providers'
|
||||||
|
|
||||||
import { authAsCognitoUser } from './authAsCognitoUser.js'
|
import { authAsCognitoUser } from './authAsCognitoUser.js'
|
||||||
|
|
||||||
export type GetStorageClient = () => Promise<{
|
export type GetStorageClient = () => Promise<{
|
||||||
identityID: string
|
identityID: string
|
||||||
storageClient: AWS.S3
|
storageClient: S3
|
||||||
}>
|
}>
|
||||||
|
|
||||||
export const refreshSession = async () => {
|
export const refreshSession = async () => {
|
||||||
@@ -33,7 +33,7 @@ export const refreshSession = async () => {
|
|||||||
// @ts-expect-error - Incorrect AWS types
|
// @ts-expect-error - Incorrect AWS types
|
||||||
const identityID = credentials.identityId
|
const identityID = credentials.identityId
|
||||||
|
|
||||||
const storageClient = new AWS.S3({
|
const storageClient = new S3({
|
||||||
credentials,
|
credentials,
|
||||||
region: process.env.PAYLOAD_CLOUD_BUCKET_REGION,
|
region: process.env.PAYLOAD_CLOUD_BUCKET_REGION,
|
||||||
})
|
})
|
||||||
|
|||||||
@@ -5,4 +5,4 @@ const nextConfig = {
|
|||||||
// Your Next.js config here
|
// Your Next.js config here
|
||||||
}
|
}
|
||||||
|
|
||||||
export default withPayload(nextConfig)
|
export default withPayload(nextConfig, { devBundleServerPackages: false })
|
||||||
|
|||||||
@@ -5,4 +5,4 @@ const nextConfig = {
|
|||||||
// Your Next.js config here
|
// Your Next.js config here
|
||||||
}
|
}
|
||||||
|
|
||||||
export default withPayload(nextConfig)
|
export default withPayload(nextConfig, { devBundleServerPackages: false })
|
||||||
|
|||||||
@@ -18,4 +18,4 @@ const nextConfig = {
|
|||||||
// transpilePackages: ['../src'],
|
// transpilePackages: ['../src'],
|
||||||
}
|
}
|
||||||
|
|
||||||
export default withPayload(nextConfig)
|
export default withPayload(nextConfig, { devBundleServerPackages: false })
|
||||||
|
|||||||
@@ -24,4 +24,4 @@ const nextConfig = {
|
|||||||
redirects,
|
redirects,
|
||||||
}
|
}
|
||||||
|
|
||||||
export default withPayload(nextConfig)
|
export default withPayload(nextConfig, { devBundleServerPackages: false })
|
||||||
|
|||||||
@@ -5,4 +5,4 @@ const nextConfig = {
|
|||||||
// Your Next.js config here
|
// Your Next.js config here
|
||||||
}
|
}
|
||||||
|
|
||||||
export default withPayload(nextConfig)
|
export default withPayload(nextConfig, { devBundleServerPackages: false })
|
||||||
|
|||||||
@@ -5,4 +5,4 @@ const nextConfig = {
|
|||||||
// Your Next.js config here
|
// Your Next.js config here
|
||||||
}
|
}
|
||||||
|
|
||||||
export default withPayload(nextConfig)
|
export default withPayload(nextConfig, { devBundleServerPackages: false })
|
||||||
|
|||||||
@@ -5,4 +5,4 @@ const nextConfig = {
|
|||||||
// Your Next.js config here
|
// Your Next.js config here
|
||||||
}
|
}
|
||||||
|
|
||||||
export default withPayload(nextConfig)
|
export default withPayload(nextConfig, { devBundleServerPackages: false })
|
||||||
|
|||||||
@@ -5,4 +5,4 @@ const nextConfig = {
|
|||||||
// Your Next.js config here
|
// Your Next.js config here
|
||||||
}
|
}
|
||||||
|
|
||||||
export default withPayload(nextConfig)
|
export default withPayload(nextConfig, { devBundleServerPackages: false })
|
||||||
|
|||||||
@@ -24,4 +24,4 @@ const nextConfig = {
|
|||||||
redirects,
|
redirects,
|
||||||
}
|
}
|
||||||
|
|
||||||
export default withPayload(nextConfig)
|
export default withPayload(nextConfig, { devBundleServerPackages: false })
|
||||||
|
|||||||
@@ -12,45 +12,48 @@ const withBundleAnalyzer = bundleAnalyzer({
|
|||||||
})
|
})
|
||||||
|
|
||||||
export default withBundleAnalyzer(
|
export default withBundleAnalyzer(
|
||||||
withPayload({
|
withPayload(
|
||||||
eslint: {
|
{
|
||||||
ignoreDuringBuilds: true,
|
eslint: {
|
||||||
},
|
ignoreDuringBuilds: true,
|
||||||
typescript: {
|
},
|
||||||
ignoreBuildErrors: true,
|
typescript: {
|
||||||
},
|
ignoreBuildErrors: true,
|
||||||
experimental: {
|
},
|
||||||
fullySpecified: true,
|
experimental: {
|
||||||
serverActions: {
|
fullySpecified: true,
|
||||||
bodySizeLimit: '5mb',
|
serverActions: {
|
||||||
|
bodySizeLimit: '5mb',
|
||||||
|
},
|
||||||
|
},
|
||||||
|
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
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
env: {
|
{ devBundleServerPackages: false },
|
||||||
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
|
|
||||||
},
|
|
||||||
}),
|
|
||||||
)
|
)
|
||||||
|
|||||||
Reference in New Issue
Block a user