Skip to content
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

feat: Provide an easily reusable Web SDK #2615

Merged
merged 1 commit into from
Jan 13, 2023
Merged

feat: Provide an easily reusable Web SDK #2615

merged 1 commit into from
Jan 13, 2023

Conversation

dcodeIO
Copy link
Member

@dcodeIO dcodeIO commented Jan 13, 2023

Using the AssemblyScript compiler on the Web currently requires multiple steps to make it work, which includes manually updating the import map on version bumps and optionally providing a shim for import maps. Instead of providing a workaround by exposing the import map in a script plus longish instructions, this PR changes the mechanism to a single script that sets everything up.

Usage is

<script src="https://cdn.jsdelivr.net/npm/assemblyscript@latest/dist/web.js"></script>
<script type="module">
import asc from "assemblyscript/asc";
...
</script>

where latest can be any version since the change, and additional query parameters can be used to modify behavior:

  • web.js?noinstall does not install the import map
  • web.js?noshim does not install the import map shim
  • Both can be combined with a ,

Regardless of the parameters used, the following global variables are always available:

  • ASSEMBLYSCRIPT_VERSION containing the current compiler version
  • ASSEMBLYSCRIPT_IMPORTMAP containing the import map, which includes all relevant versions in the URLs

Removes the web.html and importmap.js artifacts, with importmap.json (for documentation) and web.js remaining. Reverts e1a5fce.

  • I've read the contributing guidelines
  • I've added my name and email to the NOTICE file

Sorry, something went wrong.

@CountBleck
Copy link
Member

CountBleck commented Jan 13, 2023

I think you should use # instead of ? so different options don't get cached separately.

Edit: never mind, the entire URL is checked, so either works.

@dcodeIO
Copy link
Member Author

dcodeIO commented Jan 13, 2023

Yep, we could document either. Not sure about the effects in practice, though, as I think caching is per origin nowadays anyway. Could be useful if the same origin uses multiple configurations, though.

@dcodeIO dcodeIO merged commit 6a7aaef into main Jan 13, 2023
@HerrCai0907 HerrCai0907 deleted the webjs branch October 17, 2023 09:00
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants