-
Notifications
You must be signed in to change notification settings - Fork 1.5k
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
[WIP] Webpack support #1117
[WIP] Webpack support #1117
Conversation
if (typeof process === 'undefined') { | ||
process = { | ||
browser: true | ||
}; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Should be this.process = ...
?
Nice! Initial Qs:
|
To be a bit clearer on the last point, to do something like what core.js do to support partial use, so you can use only // aws-sdk/svc/s3.js
// generated by aws-sdk/dist-tools/service-loader.js
var AWS = require('../lib/aws'); // will be '../lib/browser.js' in browserify, webpack, etc...?
AWS.apiLoader.services['s3'] = {};
AWS.S3 = AWS.Service.defineService('s3', [ '2006-03-01' ]);
require('./services/s3');
AWS.apiLoader.services['s3']['2006-03-01'] = require('../apis/s3-2006-03-01.min');
AWS.apiLoader.services['s3']['2006-03-01'].paginators = require('../apis/s3-2006-03-01.paginators').pagination;
AWS.apiLoader.services['s3']['2006-03-01'].waiters = require('../apis/s3-2006-03-01.waiters2').waiters;
module.exports = AWS.S3; It... looks like it should work? |
@simonbuchan I think we can do something similar to your example. I'll take a look into that today. |
@@ -1,3 +1,11 @@ | |||
var util = require('./util'); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@chrisradek Do you think it might be worthwhile adding a buffer polyfill as well?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Absolutely. Webpack actually does polyfill buffer, but I like taking control of which buffer polyfill to use back to us (makes updating when bugs are fixed easier), and to make supporting other tools easier.
…ing the browser version of the SDK. Updated browser-builder cli to handle changes made to how the SDK loads browser services. Added crypto-browserify and buffer as dependencies to allow us greater control over deps, and to help compatibility with 3rd party tools. Added script to generate browser service files.
I added some changes to the PR. With these changes, users can require individual services and webpack/browserify will only pull those in. In the user's code, they would do something like this to require S3: var S3 = require('aws-sdk/browser/s3'); Access to the var AWS = require('aws-sdk/browser/global');
Of course, calling Today I'll be working on some documentation and some more testing. The PR shows a lot of file changes but this is largely due to generating the individual services so that they can be required individually. |
Can this be changed to just var S3 = require('aws-sdk/s3');
var AWS = require('aws-sdk/global'); Why do we need the |
@AdityaManohar I chose the I'll have to look into that issue some more to see if what's here would work for that use case as well. |
@chrisradek // main.js in my npm module
// In the past I would do this
// var AWS = require('aws-sdk');
// This is the new proposal
var S3 = require('aws-sdk/browser/s3');
var headS3Object = function() {
var s3 = new AWS.S3({region: 'us-west-2'});
s3.headObject({/*params*/}, callback);
}
module.exports = headS3Object; Using browserify: $> browserify main.js -o bundle.js This is use case that currently works with browserify, except for the selective service module inclusions. Now I could also chose to use From what you are saying, my understanding is that I cannot just take |
@AdityaManohar I might be able to create a node.js copy of the service stubs, and then in the package.json browser field map the node.js stubs to the browser ones. Then, if the user is using a tool that looks at the browser field (like webpack and browserify), the browser stubs would be used by default. I'm open to any ideas on how else to accomplish this (besides having separate packages), and I can at least go down the above route to see how feasible that is. |
var fs = require('fs'); | ||
var path = require('path'); | ||
|
||
var defaultServices = 'acm,apigateway,applicationautoscaling,autoscaling,cloudformation,cloudfront,cloudhsm,cloudtrail,cloudwatch,cloudwatchlogs,cloudwatchevents,codecommit,codedeploy,codepipeline,cognitoidentity,cognitoidentityserviceprovider,cognitosync,configservice,devicefarm,directconnect,dynamodb,dynamodbstreams,ec2,ecr,ecs,elasticache,elasticbeanstalk,elastictranscoder,elb,emr,firehose,gamelift,inspector,iotdata,kinesis,kms,lambda,marketplacecommerceanalytics,mobileanalytics,machinelearning,opsworks,rds,redshift,route53,route53domains,s3,ses,sns,sqs,ssm,storagegateway,sts,waf'; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Instead of maintaining a separate list (I know this is what we currently do anyway), we would have fewer places to worry about making manual changes for service updates if we move this information into metadata.json, e.g.
{
"acm": {
"name": "ACM",
"defaultService": true
},
...
}
That way we can also get rid of the identical identical defaultServices lists in service-collector.js as well.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Good point, I like that idea.
I'll try to send you something soon. IMO, it is a better user experience to not have to make the distinction between browser bundles and Node bundles upfront. The existing tooling ecosystem (Webpack, Browserify) largely supports writing once and running anywhere, and it would be nice if the SDK could support this out of the box as well. |
Closing in favor of #1123 |
This thread has been automatically locked since there has not been any recent activity after it was closed. Please open a new issue for related bugs and link to relevant comments in this thread. |
/cc @LiuJoyceC
This PR adds support for webpack out of the box, and maintains browserify support.
This will allow webpack to pull in the SDK with all default services, assuming no custom webpack config. There is a way to specify services with custom config but it is still a bit messy, I want to clean that up.
Tested with a personalized starter app as well as a create-react-app project.
Still a WIP. Need to test in IE, add documentation, and update tooling.
Address #603