diff --git a/packages/open-next/src/build.ts b/packages/open-next/src/build.ts index 7e6bef5e7..a72b150a6 100644 --- a/packages/open-next/src/build.ts +++ b/packages/open-next/src/build.ts @@ -489,6 +489,25 @@ async function createServerBundle(monorepoRoot: string) { injectMiddlewareGeolocation(outputPath, packagePath); removeCachedPages(outputPath, packagePath); addCacheHandler(outputPath); + + if (options.minify) { + removeNodeModule(path.join(outputPath, "node_modules"), [ + "@esbuild", + "prisma/libquery_engine-darwin-arm64.dylib.node", + "@swc/core-darwin-arm64", + "@swc/core", + "better-sqlite3", + "esbuild", + "webpack", + "uglify-js", + // "react", // TODO: remove react/react-dom when nextjs updates its precompile versions + // "react-dom", + "@webassemblyjs", + "uglify-js", + "sass", + "caniuse-lite", + ]); + } } function addMonorepoEntrypoint(outputPath: string, packagePath: string) { @@ -743,3 +762,13 @@ function compareSemver(v1: string, v2: string): number { if (minor1 !== minor2) return minor1 - minor2; return patch1 - patch2; } + +function removeNodeModule(nodeModulesPath: string, modules: string[]) { + console.log("removing: ", modules); + for (const module of modules) { + fs.rmSync(path.join(nodeModulesPath, module), { + force: true, + recursive: true, + }); + } +}