Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

performance: enable minification for the server bundles #51831

Merged
merged 7 commits into from
Jun 28, 2023
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
7 changes: 6 additions & 1 deletion packages/next/src/build/webpack-config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1766,7 +1766,11 @@ export default async function getBaseWebpackConfig(
runtimeChunk: isClient
? { name: CLIENT_STATIC_FILES_RUNTIME_WEBPACK }
: undefined,
minimize: !dev && (isClient || isEdgeServer),
minimize:
!dev &&
(isClient ||
isEdgeServer ||
(isNodeServer && config.experimental.serverMinification)),
minimizer: [
// Minify JavaScript
(compiler: webpack.Compiler) => {
Expand Down Expand Up @@ -2724,6 +2728,7 @@ export default async function getBaseWebpackConfig(
experimental: config.experimental,
disableStaticImages: config.images.disableStaticImages,
transpilePackages: config.transpilePackages,
serverSourceMaps: config.experimental.serverSourceMaps,
})

// @ts-ignore Cache exists
Expand Down
1 change: 1 addition & 0 deletions packages/next/src/build/webpack/config/blocks/base.ts
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ export const base = curry(function base(
} else {
if (
ctx.isEdgeRuntime ||
(ctx.isServer && ctx.serverSourceMaps) ||
// Enable browser sourcemaps:
(ctx.productionBrowserSourceMaps && ctx.isClient)
) {
Expand Down
3 changes: 3 additions & 0 deletions packages/next/src/build/webpack/config/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ export async function buildConfiguration(
transpilePackages,
experimental,
disableStaticImages,
serverSourceMaps,
}: {
hasAppDir: boolean
supportedBrowsers: string[] | undefined
Expand All @@ -41,6 +42,7 @@ export async function buildConfiguration(
future: NextConfigComplete['future']
experimental: NextConfigComplete['experimental']
disableStaticImages: NextConfigComplete['disableStaticImages']
serverSourceMaps: NextConfigComplete['experimental']['serverSourceMaps']
}
): Promise<webpack.Configuration> {
const ctx: ConfigurationContext = {
Expand All @@ -64,6 +66,7 @@ export async function buildConfiguration(
transpilePackages,
future,
experimental,
serverSourceMaps: serverSourceMaps ?? false,
}

let fns = [base(ctx), css(ctx)]
Expand Down
1 change: 1 addition & 0 deletions packages/next/src/build/webpack/config/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ export type ConfigurationContext = {

sassOptions: any
productionBrowserSourceMaps: boolean
serverSourceMaps: boolean

transpilePackages: NextConfigComplete['transpilePackages']

Expand Down
6 changes: 6 additions & 0 deletions packages/next/src/server/config-schema.ts
Original file line number Diff line number Diff line change
Expand Up @@ -512,6 +512,12 @@ const configSchema = {
logging: {
type: 'string',
},
serverMinification: {
type: 'boolean',
},
serverSourceMaps: {
type: 'boolean',
},
},
type: 'object',
},
Expand Down
12 changes: 12 additions & 0 deletions packages/next/src/server/config-shared.ts
Original file line number Diff line number Diff line change
Expand Up @@ -287,6 +287,16 @@ export interface ExperimentalConfig {
* Allows adjusting body parser size limit for server actions.
*/
serverActionsBodySizeLimit?: SizeLimit

/**
* enables the minification of server code.
*/
serverMinification?: boolean

/**
* Enables source maps generation for the server production bundle.
*/
serverSourceMaps?: boolean
}

export type ExportPathMap = {
Expand Down Expand Up @@ -670,6 +680,8 @@ export const defaultConfig: NextConfig = {
output: !!process.env.NEXT_PRIVATE_STANDALONE ? 'standalone' : undefined,
modularizeImports: undefined,
experimental: {
serverMinification: false,
serverSourceMaps: false,
caseSensitiveRoutes: false,
useDeploymentId: false,
deploymentId: undefined,
Expand Down
Loading