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: reduce sourcemaps and visualize dep tree #1

Open
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

rehanvdm
Copy link

This PR adds two features

Includng reduces sourcemaps

Excluding sourcemaps and shipping them to your third-party provider is great, but for Lambdas using CloudWatch, you have to include them to get meaningful traces.

This PR shows how you can drastically reduce the source maps by excluding anything from node_modules/ shrinking the souremap file from 34K to 2.2K.

Size Before

rehanvandermerwe@Rehans-MBP lambda-template % ls -lsha dist/products
total 120
 0 drwxr-xr-x  5 rehanvandermerwe  staff   160B Nov 19 11:46 .
 0 drwxr-xr-x  4 rehanvandermerwe  staff   128B Nov 19 11:46 ..
16 -rw-r--r--  1 rehanvandermerwe  staff   7.0K Nov 19 11:46 handler.js
72 -rw-r--r--  1 rehanvandermerwe  staff    34K Nov 19 11:46 handler.js.map
32 -rw-r--r--  1 rehanvandermerwe  staff    13K Nov 19 11:46 products.zip

Size After

rehanvandermerwe@Rehans-MBP lambda-template % ls -lsha dist/products                                                             
total 32
 0 drwxr-xr-x  5 rehanvandermerwe  staff   160B Nov 19 11:36 .
 0 drwxr-xr-x  4 rehanvandermerwe  staff   128B Nov 19 11:36 ..
16 -rw-r--r--  1 rehanvandermerwe  staff   7.0K Nov 19 11:36 handler.js
 8 -rw-r--r--  1 rehanvandermerwe  staff   2.2K Nov 19 11:36 handler.js.map
 8 -rw-r--r--  1 rehanvandermerwe  staff   3.9K Nov 19 11:36 products.zip

Visualize esbuild bundle

Similar to webpack, we can visualize our bundle, with a bit of work. It will open the bundle analysis as a HTML file after each build.

Example:
image

Copy link
Owner

@bruuuuuuuce bruuuuuuuce left a comment

Choose a reason for hiding this comment

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

@rehanvdm thanks for this pr, this looks great! I pulled it down and tested it locally and everything looks good from my end. Really appreciate the feedback and analysis! I left one comment about a dependency, but once that is resolved I can merge this. Thanks again!

"serverless": "^3.36.0",
"serverless-better-credentials": "^2.0.0",
"ts-node": "^10.9.1",
"typescript": "^5.2.2"
},
"dependencies": {
"aws-lambda": "^1.0.7",
"lambda-log": "^3.1.0"
"lambda-log": "^3.1.0",
"open": "^8.4.2"
Copy link
Owner

Choose a reason for hiding this comment

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

I believe this should be a dev dependency

Copy link
Author

Choose a reason for hiding this comment

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

It can be yes, I mainly opened it to show what is possible. From the blog article, it seemed that you don't want to ship the sourcemaps with? So my idea with this PR wasn't that it will get merged, just to show that it is possible. Else if merged you would have to change parts of the article?

If not and you do want to merge it, by all means :). Please feel free to make the small change above or I can as well.

Nice article btw :). Also FYI, I created two issues that will/might turn into PRs upstream on the CDK:

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants