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鈥檒l occasionally send you account related emails.

Already on GitHub? Sign in to your account

Importing the getDiscordSecrets function results in 3 MB JS bundle #4

Open
timbru31 opened this issue May 16, 2021 · 7 comments
Open
Labels
enhancement New feature or request

Comments

@timbru31
Copy link
Contributor

Really appreciate the fixes you've made in the last hours 馃憤

However, there seems to be an issue with the tree shaking I assume.
Importing from
import { getDiscordSecrets } from "discord-bot-cdk-construct";
results in a 13 MB big lambda file.

Changing the import to
import { getDiscordSecrets } from "discord-bot-cdk-construct/dist/functions/utils/DiscordSecrets";
workarounds the problem.

I've noticed your oculus-start-bot still relies on a local version of the function, too, so this might went under your radar.

@GEMISIS
Copy link
Owner

GEMISIS commented May 17, 2021

Hmm... I don't seem to be able to reproduce this? I don't believe this should be caused by include the Discord secrets, as even the DiscordBotFunction's Lambda is fairly small (17.1kB for me). Can you post your Lambda code that you're seeing this issue with?

I saw you removed another reference to the oculus-start-bot, appreciate that! That's my main test playground atm, so yeah, a few references were from there 馃槄

@timbru31
Copy link
Contributor Author

I'll prepare a minimum reproducible repository for you to test 馃憤

@timbru31
Copy link
Contributor Author

Here you go:
https://github.com/timbru31/DiscordBotCDKConstructIssue4

I've basically made an empty skeleton with cdk init and added the example lambda function from the README. (https://github.com/timbru31/DiscordBotCDKConstructIssue4/blob/master/lib/functions/lambda.ts).
If you do an npm i && cdk synth you should notice that the CommandsLambda is way too big.

@timbru31
Copy link
Contributor Author

Not 100% sure but this might be caused by depending on axios? (see

"axios": "^0.21.1",
)

Probably the construct itself doesn't need this dependency anyways?!

@GEMISIS
Copy link
Owner

GEMISIS commented May 18, 2021

So I'm still not able to reproduce this, even with your repo as shown.

image

This sounds like something odd in your setup specifically? Are you on the latest CDK CLI version? Also, you've built the package with npm run build beforehand right? Nothing weird like that causing issues?

@timbru31
Copy link
Contributor Author

timbru31 commented May 18, 2021

You were able to reproduce it! 馃帀
The zip is half a megabyte and I bet if you unpack it, it will be around 3mb.

CDK is at 1.104.0 (build 44d3383), Node.js v14.16.1. No, I did just run cdk synth, as far as I've understood it automatically uses esbuild under the hood to transpile the TS code to JS

@GEMISIS GEMISIS changed the title Importing the getDiscordSecrets function results in 13 MB JS bundle Importing the getDiscordSecrets function results in 3 MB JS bundle May 23, 2021
@GEMISIS
Copy link
Owner

GEMISIS commented May 23, 2021

Gotcha, okay, you'd mentioned this was 13MB, but 3MB is different and a bit more acceptable for something like this right now (axios seems like it might be a likely candidate, as it's only blowing up the size of the commands lambda, not the discord one). I've updated the title of this to accurately reflect this and will take a look, though this isn't super high priority, as I'm sure that there's some

@GEMISIS GEMISIS added the enhancement New feature or request label Apr 1, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

2 participants