Skip to content

Use Web SDK in editor #190

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

Merged
merged 3 commits into from
Jan 14, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 1 addition & 19 deletions src/.vuepress/public/editor.html
Original file line number Diff line number Diff line change
Expand Up @@ -312,25 +312,7 @@ <h5>Documentation</h5>
</div>
<input type="text" id="clipboardHelper" aria-hidden="true" />
<script src="https://cdn.jsdelivr.net/npm/[email protected]/min/vs/loader.js"></script>
<script async src="https://cdn.jsdelivr.net/npm/es-module-shims@1/dist/es-module-shims.wasm.min.js"></script>
<script type="importmap">
{
"imports": {
"assemblyscript": "https://cdn.jsdelivr.net/npm/assemblyscript@latest/dist/assemblyscript.js",
"assemblyscript/asc": "https://cdn.jsdelivr.net/npm/assemblyscript@latest/dist/asc.js",
"binaryen": "https://cdn.jsdelivr.net/npm/[email protected]/index.js",
"long": "https://cdn.jsdelivr.net/npm/[email protected]/index.min.js"
},
"scopes": {
"https://cdn.jsdelivr.net/npm/assemblyscript/": {
"fs": "./scripts/empty.js",
"module": "./scripts/empty.js",
"path": "./scripts/empty.js",
"url": "./scripts/empty.js"
}
}
}
</script>
<script src="https://cdn.jsdelivr.net/npm/assemblyscript@latest/dist/web.js"></script>
<script type="module">
import asc from "assemblyscript/asc";

Expand Down
Empty file.
28 changes: 15 additions & 13 deletions src/compiler.md
Original file line number Diff line number Diff line change
Expand Up @@ -246,28 +246,30 @@ if (error) {
}
```

With import maps, the compiler runs in browsers as well:
The compiler runs in browsers as well. The simplest way to set it up is to include the generated [web.js](https://cdn.jsdelivr.net/npm/assemblyscript@latest/dist/web.js) so the compiler can be used with an `import` on the Web:

```html
<script async src="https://cdn.jsdelivr.net/npm/es-module-shims@1/dist/es-module-shims.js"></script>
<script type="importmap">
{
"imports": {
"assemblyscript": "https://cdn.jsdelivr.net/npm/[email protected]/dist/assemblyscript.js",
"assemblyscript/asc": "https://cdn.jsdelivr.net/npm/[email protected]/dist/asc.js",
"binaryen": "https://cdn.jsdelivr.net/npm/[email protected]/index.js",
"long": "https://cdn.jsdelivr.net/npm/[email protected]/index.js"
}
}
</script>
<script src="https://cdn.jsdelivr.net/npm/[email protected]/dist/web.js"></script>
<script type="module">
import asc from "assemblyscript/asc";
...
</script>
```

Note that the matching versions of the respective dependencies need to be filled in instead of `x.x.x`. Current versions can be obtained from the generated [importmap.json](https://cdn.jsdelivr.net/npm/assemblyscript@latest/dist/importmap.json) file. The [es-module-shims](https://github.com/guybedford/es-module-shims) dependency polyfills support for import maps where not yet available.
Here, `x.x.x` must be replaced with the [respective version to use](https://github.com/AssemblyScript/assemblyscript/tags), or `latest` to always use the latest version (not recommended in production). By default, the script installs [the necessary import map](https://cdn.jsdelivr.net/npm/assemblyscript@latest/dist/importmap.json) and, for browsers that do not yet support import maps, [an import map shim](https://github.com/guybedford/es-module-shims). It also accepts the following options in case there is a need to only perform part of the setup:

| Script URL | Effect
|---------------------------|------------------------------------------
| `web.js?noinstall` | Does not install the import map.
| `web.js?noshim` | Does not install the import map shim.
| `web.js?noinstall,noshim` | Does not install the import map or shim.

Regardless of the options used, the script always declares the following global variables:

| Variable | Description
|----------------------------|-------------------------------------------------
| `ASSEMBLYSCRIPT_VERSION` | Version string of the compiler release used
| `ASSEMBLYSCRIPT_IMPORTMAP` | The respective import map of the release as JSON

## Host bindings

Expand Down