amazon-archives / amazon-cognito-js

Amazon Cognito Sync Manager for JavaScript
http://aws.amazon.com/cognito
Apache License 2.0
202 stars 83 forks source link

final bundle size is quite large #47

Open jonknapp opened 7 years ago

jonknapp commented 7 years ago

Feel free to close this out if things are working as intended, but in a fresh app created with create-react-app requiring this library adds almost 2 MBs of code to the final bundle size. To contrast, adding the amazon-cognito-identity-js library adds only 0.08 MBs.

I would imagine the scope of what each library does is drastically different, but I'm wondering if there is something else that can be done to cut back on the final bundle size. Possibly moving some of the more barebones methods to their own module that we can include directly.

jonknapp commented 7 years ago

This additional increase to the bundle may be a side effect of running it through webpack / babel as well. I'm a little light on exactly why it's happening, just thought it worthwhile to bring it up since I didn't see it mentioned anywhere else.

itrestian commented 7 years ago

You probably end up including the whole AWS SDK.

Basically this is the way you build only the necessary clients for the AWS SDK:

http://docs.aws.amazon.com/sdk-for-javascript/v2/developer-guide/building-sdk-for-browsers.html

node dist-tools/browser-builder.js

and specify the services you want to include.

jonknapp commented 7 years ago

If this library includes the full AWS lib (or it was implicitly done via webpack) that may be it. My only other AWS require in the app was aws-sdk/global which added about 0.6 MBs.

jonknapp commented 7 years ago

I think you are correct about the entire AWS lib being included. I have some code that avoids webpack and includes the minified version of this lib in another script tag and that was causing errors until I brought in the aws-sdk/clients/cognitosync library. When I was requiring this library through webpack before, it did not give the errors about the CognitoSync client.

I'm not sure where webpack / babel-loader is trying to pull in the full AWS library from this dist file's source though.

jonknapp commented 7 years ago

Ah, looks like a new NPM version was not published after the change to remove the bulk of AWS sdk from the minified version of this lib: https://github.com/aws/amazon-cognito-js/commit/47f6b8a52d703d9249e4a63ffcadc5a896e6c972

It would probably work for me as expected after a new release is cut that includes this fix.

orzechowskid commented 6 years ago

any chance we could get a new version of this package published to NPM? I'd love to get the bundle size fix that's been discussed here, and even though putting a GitHub commit hash in my package.json is supported and works it still feels a little dirty to have it there.

DavidWells commented 6 years ago

@orzechowskid whats the dependency look like in your package.json?

I'd like to shrink my bundle as well =)

orzechowskid commented 6 years ago

@DavidWells b57038c is the latest commit to amazon-cognito-js as of today:

"dependencies": {
-  "amazon-cognito-js": "^1.1.0"
+  "amazon-cognito-js": "aws/amazon-cognito-js#b57038ca817981a60bd8b26c2ddaff27c81b908a"
}
alexjfno1 commented 5 years ago

Just been looking at my bundle size and it seems #38 hasn't been released to NPM. Can someone release the latest code to NPM?

christemple commented 5 years ago

@itrestian can we please get a new version of this packaged published with the changes?

I'd prefer not to pull from a github commit in my package.json