From df76f6633fe192e04b88ace62a00ccc9bb833d86 Mon Sep 17 00:00:00 2001 From: Jimmy Lai Date: Mon, 11 Sep 2023 14:23:02 +0200 Subject: [PATCH] server: remove turbopack-specific code when compiling with webpack (#55226) This PR tweaks the webpack config so that when we compile user code with webpack, we remove all branches of code that are guarded with `process.env.TURBOPACK`. I noticed that the bundle runtime was not tree-shaken correctly, this fixes that. --- packages/next/src/build/webpack-config.ts | 1 + packages/next/webpack.config.js | 1 + 2 files changed, 2 insertions(+) diff --git a/packages/next/src/build/webpack-config.ts b/packages/next/src/build/webpack-config.ts index d1b7487618fe2..dbc805edaf1fd 100644 --- a/packages/next/src/build/webpack-config.ts +++ b/packages/next/src/build/webpack-config.ts @@ -371,6 +371,7 @@ export function getDefineEnv({ 'global.GENTLY': JSON.stringify(false), } : undefined), + 'process.env.TURBOPACK': JSON.stringify(false), } } diff --git a/packages/next/webpack.config.js b/packages/next/webpack.config.js index 8e7c3063fa5ed..83fe9d3009877 100644 --- a/packages/next/webpack.config.js +++ b/packages/next/webpack.config.js @@ -131,6 +131,7 @@ module.exports = ({ dev, turbo }) => { dev ? 'development' : 'production' ), 'process.env.NEXT_RUNTIME': JSON.stringify('nodejs'), + ...(!dev ? { 'process.env.TURBOPACK': JSON.stringify(turbo) } : {}), }), !!process.env.ANALYZE && new BundleAnalyzerPlugin({