├── .gitignore
├── Sources
├── LibraryCode
│ └── LibraryCode.swift
└── BrowserApp
│ └── main.swift
├── Tests
└── BrowserAppTests
│ └── BrowserAppTests.swift
├── .github
├── workflows
│ ├── test.yml
│ └── deploy.yml
└── FUNDING.yml
├── Package.resolved
├── Package.swift
└── README.md
/.gitignore:
--------------------------------------------------------------------------------
1 | .DS_Store
2 | /.build
3 | /Packages
4 | /*.xcodeproj
5 | xcuserdata/
6 |
--------------------------------------------------------------------------------
/Sources/LibraryCode/LibraryCode.swift:
--------------------------------------------------------------------------------
1 | public func div(_ content: String) -> String {
2 | "
\(content)
"
3 | }
4 |
--------------------------------------------------------------------------------
/Tests/BrowserAppTests/BrowserAppTests.swift:
--------------------------------------------------------------------------------
1 | import LibraryCode
2 | import XCTest
3 |
4 | final class BrowserAppTests: XCTestCase {
5 | func testDiv() {
6 | XCTAssertEqual(div("42"), "42
")
7 | }
8 | }
9 |
--------------------------------------------------------------------------------
/.github/workflows/test.yml:
--------------------------------------------------------------------------------
1 | name: Test with SwiftWasm
2 |
3 | on:
4 | pull_request:
5 | push:
6 | branches: [main]
7 |
8 | jobs:
9 | swiftwasm_test:
10 | runs-on: ubuntu-20.04
11 |
12 | steps:
13 | - uses: actions/checkout@v2
14 | - uses: swiftwasm/swiftwasm-action@v5.3
15 | with:
16 | shell-action: carton test
17 |
--------------------------------------------------------------------------------
/Package.resolved:
--------------------------------------------------------------------------------
1 | {
2 | "object": {
3 | "pins": [
4 | {
5 | "package": "JavaScriptKit",
6 | "repositoryURL": "https://github.com/swiftwasm/JavaScriptKit",
7 | "state": {
8 | "branch": null,
9 | "revision": "b7a02434c6e973c08c3fd5069105ef44dd82b891",
10 | "version": "0.9.0"
11 | }
12 | }
13 | ]
14 | },
15 | "version": 1
16 | }
17 |
--------------------------------------------------------------------------------
/.github/workflows/deploy.yml:
--------------------------------------------------------------------------------
1 | name: Deploy to GitHub Pages
2 |
3 | on:
4 | push:
5 | branches: [main]
6 |
7 | jobs:
8 | swiftwasm_deploy:
9 | runs-on: ubuntu-20.04
10 |
11 | steps:
12 | - uses: actions/checkout@v2
13 |
14 | - uses: swiftwasm/swiftwasm-action@v5.3
15 | with:
16 | shell-action: carton bundle
17 |
18 | - name: Deploy
19 | uses: peaceiris/actions-gh-pages@v3
20 | with:
21 | github_token: ${{ secrets.GITHUB_TOKEN }}
22 | publish_dir: ./Bundle
23 |
--------------------------------------------------------------------------------
/Package.swift:
--------------------------------------------------------------------------------
1 | // swift-tools-version:5.3
2 | import PackageDescription
3 | let package = Package(
4 | name: "BrowserApp",
5 | products: [
6 | .executable(name: "BrowserApp", targets: ["BrowserApp"])
7 | ],
8 | dependencies: [
9 | .package(name: "JavaScriptKit", url: "https://github.com/swiftwasm/JavaScriptKit", from: "0.9.0")
10 | ],
11 | targets: [
12 | .target(
13 | name: "BrowserApp",
14 | dependencies: [
15 | .product(name: "JavaScriptKit", package: "JavaScriptKit")
16 | ]),
17 | .target(name: "LibraryCode"),
18 | .testTarget(
19 | name: "BrowserAppTests",
20 | dependencies: ["LibraryCode"]),
21 | ]
22 | )
--------------------------------------------------------------------------------
/.github/FUNDING.yml:
--------------------------------------------------------------------------------
1 | # These are supported funding model platforms
2 |
3 | github: [swiftwasm] # Replace with up to 4 GitHub Sponsors-enabled usernames e.g., [user1, user2]
4 | patreon: # Replace with a single Patreon username
5 | open_collective: swiftwasm # Replace with a single Open Collective username
6 | ko_fi: # Replace with a single Ko-fi username
7 | tidelift: # Replace with a single Tidelift platform-name/package-name e.g., npm/babel
8 | community_bridge: # Replace with a single Community Bridge project-name e.g., cloud-foundry
9 | liberapay: # Replace with a single Liberapay username
10 | issuehunt: # Replace with a single IssueHunt username
11 | otechie: # Replace with a single Otechie username
12 | custom: # Replace with up to 4 custom sponsorship URLs e.g., ['link1', 'link2']
13 |
--------------------------------------------------------------------------------
/Sources/BrowserApp/main.swift:
--------------------------------------------------------------------------------
1 | import JavaScriptKit
2 |
3 | let document = JSObject.global.document
4 |
5 | var divElement = document.createElement("div")
6 | divElement.innerHTML = #"""
7 | Welcome to SwiftWasm! Check out the SwiftWasm book if you're just getting started.
9 |
10 |
11 | This template provides a basic setup for an
13 | app built with SwiftWasm and JavaScriptKit.
14 |
15 | Check out Tokamak if you prefer a high-level API for building
16 | browser apps. It is also compatible with SwiftUI, which allows you to build your apps for multiple
17 | platforms.
18 | """#
19 |
20 | _ = document.body.appendChild(divElement)
21 |
--------------------------------------------------------------------------------
/README.md:
--------------------------------------------------------------------------------
1 | # A basic browser app built with [SwiftWasm](https://swiftwasm.org)
2 |
3 | [`carton`](https://carton.dev) is the recommended way to build and run browser apps built with
4 | SwiftWasm. Follow these steps to get started, where you'll install `carton` via
5 | [Homebrew](https://brew.sh/) on macOS (unfortunately you'll have to build it manually on Linux).
6 | After you already have Homebrew installed, just these three steps will get you up and running:
7 |
8 | 1. Install `carton`:
9 |
10 | ```
11 | brew install swiftwasm/tap/carton
12 | ```
13 |
14 | If you had `carton` installed before this, make sure you have version 0.9.0 or greater:
15 |
16 | ```
17 | carton --version
18 | ```
19 |
20 | 2. Build the project and start the development server, `carton dev` can be kept running
21 | during development:
22 |
23 | ```
24 | carton dev
25 | ```
26 |
27 | 3. After the build succeeds, a page on a development server will open automatically, or you can
28 | navigate to [http://127.0.0.1:8080/](http://127.0.0.1:8080/) in your browser manually to see the
29 | app running. You can edit the app source code in your favorite editor and save it, `carton` will
30 | immediately rebuild the app and reload all browser tabs that have the app open.
31 |
32 | ## Deployment
33 |
34 | You can easily deploy SwiftWasm apps to [GitHub Pages](https://pages.github.com). This repository
35 | is already set up to do so. If you have GitHub Actions enabled, it will push successful builds to
36 | the `gh-pages` branch on every commit. You only need [to enable GitHub Pages in settings of your
37 | repository](https://docs.github.com/en/free-pro-team@latest/github/working-with-github-pages/configuring-a-publishing-source-for-your-github-pages-site#choosing-a-publishing-source) and select `gh-pages` branch as your publishing source.
38 |
39 | You can also deploy the app to any other CDN or hosting that can serve static files. Just run
40 | `carton bundle` in the root directory of this repository clone. This will create a `Bundle`
41 | directory that contains everything you need for the app to work. Then copy the contents of that
42 | directory to wherever you'd like to host it.
43 |
--------------------------------------------------------------------------------