Reputation: 14606
I'm using the aws-sdk in my Angular application. The bundle size is HUGE, and I'm only using a tiny fraction of the library:
Question: Is there any way to only partially import aws-sdk?
Please note:
import * as AWS from 'aws-sdk';
Upvotes: 3
Views: 621
Reputation: 1056
In my application I use only S3. And I managed to reduce the size of the bundle as follows:
import AWS from 'aws-sdk/global';
import S3 from 'aws-sdk/clients/s3';
//Here is an example of code used to perform file upload.
AWS.config.update({
accessKeyId: "YOUR-ACCESS-KEY",
secretAccessKey: "YOUR-SECRET",
"region": "us-east-1"
});
var file = document.getElementById("input-upload").files[0];
var bucket = new S3({params: {Bucket: 'mybucket'}});
var params = {Key: 'myfolder', ContentType: file.type, Body: file};
bucket.upload(params);
Upvotes: 0
Reputation: 2454
From the docs, you can import individual parts of the AWS SDK like so:
// import individual service
import S3 from 'aws-sdk/clients/s3';
You'll need to consult the documentation / type definitions to see what the ones you want are called exactly.
Avoid importing the whole "aws-sdk" package as this won't be tree shaken
Upvotes: 1