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

feat: remove dev node_modules deps #242

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
29 changes: 29 additions & 0 deletions packages/open-next/src/build.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

my logs:
image
can we remove some of them also?

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Very likely yes, but you'll need to test for yourself. You can probably remove :

  • swc core
  • sharp
  • esbuild
  • caniuse lite
  • uglify-js
  • terser

"prisma/libquery_engine-darwin-arm64.dylib.node",
Copy link
Contributor

@sladg sladg Sep 21, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

can we include all prisma engines?

meaning all other OS packages not compatible with Lambda

Copy link
Collaborator Author

@khuezy khuezy Sep 21, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do you know where I can get a list of all non-lambda engines?
I might need to update this and use micromatch to allow for negation...

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Honestly, what the hell is wrong with prisma?

"@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",
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Duplicate here, it's also listed above!

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thx, I'll have to retest this w/ Next 14, which seems to have fixed the dev deps getting traced to the standalone output.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Been busy last week and caught a cold this week... I'll eventually test this to confirm... @mathisobadia was still seeing these dev modules but I didn't...

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Here's my server function lambda zip, on Next 14.0.2:

image

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@revmischa This is inside your server-function lambda ? There is a lot of things that you should be able to remove, you can use experimental.outputFileTracingExcludes from next config to remove all of those.
You should probably create an issue in next repo as well, those dev deps should have been removed.

"sass",
"caniuse-lite",
]);
}
}

function addMonorepoEntrypoint(outputPath: string, packagePath: string) {
Expand Down Expand Up @@ -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,
});
}
}