amazon-archives/amazon-cognito-js

final bundle size is quite large

jonknapp opened this issue ยท 10 comments

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.

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.

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.

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.

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.

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: 47f6b8a

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

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.

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

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

@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"
}

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?

@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