-
Notifications
You must be signed in to change notification settings - Fork 126
Commit
* Add e2e test instructions; Add documentation on bundle size
- Loading branch information
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,55 @@ | ||
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! | ||
This comment has been minimized.
Sorry, something went wrong.
This comment has been minimized.
Sorry, something went wrong.
feedthejim
|
||
|
||
Add this to your next.config.js to help minimize the lambda bundle size: | ||
|
||
```typescript | ||
outputFileTracingExcludes: { | ||
'*': [ | ||
'@swc/core', | ||
'esbuild', | ||
'uglify-js', | ||
'watchpack', | ||
'webassemblyjs', | ||
'sharp' | ||
], | ||
}, | ||
``` | ||
|
||
<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> | ||
|
||
#### Common issues | ||
|
||
##### Sharp | ||
|
||
`sharp` is not needed outside of the `Image Optimization` function so you should not have it as a dependency. But if you are depending on `sharp`, be sure to install it with the correct flags for your lambda. | ||
eg: `--arch=arm64 --platform=linux --target=18 --libc=glibc` | ||
|
||
##### pdfjs | ||
|
||
If you need to use pdfjs, you should install it with `npm i pdfjs-dist--no-optional` because the optional dep: `canvas` takes about 180MB. | ||
|
||
##### Others | ||
|
||
Please open an issue or let us know on discord if there are any other modules that are causing issues. |
1 comment
on commit d291e6a
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.
Successfully deployed to the following URLs:
open-next – ./
open-next-git-main-sst-dev.vercel.app
open-next.vercel.app
open-next-sst-dev.vercel.app
hey @khuezy, someone sent me this link. I'm fairly confident this is not correct, are you not using the NFT files to get the files needed for the lambda?