{"id":13725301,"url":"https://github.com/grain-lang/grain-web-example","last_synced_at":"2025-04-14T21:03:14.364Z","repository":{"id":47176802,"uuid":"278956879","full_name":"grain-lang/grain-web-example","owner":"grain-lang","description":"An example using Grain in the browser.","archived":false,"fork":false,"pushed_at":"2021-09-09T19:36:26.000Z","size":915,"stargazers_count":11,"open_issues_count":0,"forks_count":4,"subscribers_count":8,"default_branch":"master","last_synced_at":"2024-11-21T17:25:46.422Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":null,"language":"JavaScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/grain-lang.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":null,"code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2020-07-11T23:17:56.000Z","updated_at":"2023-11-08T22:59:45.000Z","dependencies_parsed_at":"2022-09-01T15:43:33.592Z","dependency_job_id":null,"html_url":"https://github.com/grain-lang/grain-web-example","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/grain-lang%2Fgrain-web-example","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/grain-lang%2Fgrain-web-example/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/grain-lang%2Fgrain-web-example/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/grain-lang%2Fgrain-web-example/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/grain-lang","download_url":"https://codeload.github.com/grain-lang/grain-web-example/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":226856924,"owners_count":17693016,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":[],"created_at":"2024-08-03T01:02:18.639Z","updated_at":"2024-11-28T04:16:20.132Z","avatar_url":"https://github.com/grain-lang.png","language":"JavaScript","funding_links":[],"categories":["JavaScript"],"sub_categories":[],"readme":"# Grain Web Example\n\nThis repo contains an example of Grain wasm files running in a browser.\n\n## Setup\n\nFirst, you'll need to install the Grain compiler by following the [Getting Grain](https://grain-lang.org/docs/getting_grain) guide for your operating system.\n\nAdditionally, you'll need to install the project dependencies using:\n\n```sh\nnpm install\n```\n\nThe easiest way to compile your Grain files to WebAssembly is to use the built-in npm script:\n\n```sh\nnpm run compile\n```\n\nThis will compile `hello.gr`, `another.gr`, and the necessary stdlib dependencies.\n\nThen, run a webserver in this directory. You can use our other npm script:\n\n```sh\nnpm start\n```\n\n(This script will also compile your project before starting the webserver).\n\nIf you visit `localhost:1337` and open your dev console, you should see the hello world messages appear.\n\n## `index.html` Breakdown\n\nWe first load the Grain browser runtime with this script tag:\n\n```html\n\u003cscript src=\"node_modules/@grain/js-runner/dist/grain-runner-browser.js\"\u003e\u003c/script\u003e\n```\n\n`Grain.buildGrainRunner` takes a locator function as its argument. In this case, we just use the `defaultURLLocator`. As arguments, we pass the locations to look for wasm files—the current URL as the root, and the `node_modules/@grain/stdlib` subdirectory. The default locator will try to find wasm files by first looking in the root of this project, followed by the stdlib directory.\n\nOnce the `GrainRunner` is set up, we call `GrainRunner.runURL` with `hello.wasm`. The locator will then fetch `hello.wasm`, see that it depends on `another.wasm` and `pervasives.wasm`, and load those as well.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fgrain-lang%2Fgrain-web-example","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fgrain-lang%2Fgrain-web-example","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fgrain-lang%2Fgrain-web-example/lists"}