-
Notifications
You must be signed in to change notification settings - Fork 64
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
add browser build for sdk #3756
Conversation
packages/cardpay-sdk/package.json
Outdated
@@ -5,6 +5,7 @@ | |||
"author": "Hassan Abdel-Rahman @habdelra", | |||
"main": "./dist/esm/index.js", | |||
"types": "./dist/index.d.ts", | |||
"browser": "browser.js", |
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.
im think I will remove this. Because consumers of the sdk may look for different keys depending on their target. I think webpack default behaviour may be to prefer "browser" over "main", but i think there are complex set of rules that decide this.
- "resolve.mainFields" can specify the priority eg ["browser", "main"] for consumers of the sdk but I think this affects other dependencies (bad)
- another way is to use
alias
to point to the specific main file of the sdk (ok) - For my purposes, since I can point to the correct file (even using unpkg), there is no need to have this key. (probably best)
I used this to test the claim in browser
|
@@ -59,6 +59,7 @@ package-lock.json | |||
/packages/cardpay-sdk/**/*.js.map | |||
/packages/cardpay-sdk/generated/ | |||
# Let's keep this though! | |||
!/packages/cardpay-sdk/scripts/browser-build.js |
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.
why do we want to commit the build artifacts to git? isn't that what the !
does?
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.
Oh this is the script NOT the build. previously js files was being ignored
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.
Ah, got it!
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.
you can always just write it in typescript and then use ts-node to execute it too. but js is fine for this purpose.
in terms of the CDN you can include a deploy script to deploy it to some bucket on s3, that is projected to cloudfront (I'm not sure which bucket or which cloudfront we'd want to use, probably we could talk to @pcjun97 about that). Otherwise, the act of doing an npm publish with this new browser artifact will ultimately trigger unpkg to pick it up. |
This PR makes a browser build of the sdk (standalone). The sdk is expected to work in browser. I use esbuild since we use a lot of tsup (esbuild under the hood). Esbuild is simpler and faster. This will build a minified
browser.js
with sourcemap in thedist
folder of the sdk when callingyarn prepack
.