-
Notifications
You must be signed in to change notification settings - Fork 143
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
docs: add documentation on minimizing lambda bundle #167
Changes from 1 commit
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
import {Callout} from 'nextra/components' | ||
|
||
|
||
#### Reducing Bundle Size | ||
|
||
Next will incorrectly trace dev dependencies to be included in the output `node_modules`, which will significantly increase the lambda bundle. For example, the @swc/core-\* binary is ~33MB! | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. With 13.5.1+ they probably will not even end up in There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I built w/ 13.5.4 and the |
||
|
||
Add this to your next.config.js to help minimize the lambda bundle size: | ||
|
||
```typescript | ||
outputFileTracingExcludes: { | ||
'*': [ | ||
'@swc/core', | ||
'esbuild', | ||
'uglify-js', | ||
'watchpack', | ||
'webassemblyjs' | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. We could probably add sharp here, people might have installed but it's not needed outside of the image optimization function. |
||
], | ||
}, | ||
``` | ||
|
||
<Callout type="warning" emoji="⚠️"> | ||
NextJS currently doesn't expose `outputFileTracingExcludes` as an environmental variable so `open-next`cannot programmatically set this like it does for`output`and`outputFileTracingRoot`. | ||
Currently, next uses `webpack` to trace server actions, so you shouldn't add `webpack` to the excludes list, otherwise it will break server actions. | ||
</Callout> | ||
|
||
#### Unzipped size must be smaller than 262144000 bytes | ||
|
||
To identify the module that's taking up too much space (and isn't serverless friendly): | ||
|
||
```bash | ||
du -hs .open-next/server-function/node_modules/* | sort -rh | ||
``` | ||
|
||
If your app requires the offending library, then consider moving your business logic of the `api` to its own lambda, eg: `/api/v2` => `Api Lambda` | ||
|
||
<Callout type="info" emoji="ℹ️"> | ||
There is a [PR](https://github.com/sst/open-next/pull/242) to remove some dev dependency from the output node_modules but that requires more testing before it can merge. | ||
</Callout> |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Maybe add that what's important is the
.open-next/server-function
folder, and the rest are mostly irrelevant.We could also add that a big bundle size will increase cold start a lot