Skip to content

Commit 4b54032

Browse files
committed
Refactor import statements, add support for binary files, and update dependencies
1 parent f4f271f commit 4b54032

File tree

6 files changed

+17
-22
lines changed

6 files changed

+17
-22
lines changed

assets/assets.d.ts

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
// binary
2+
declare module "*.wasm" {
3+
const value: Uint8Array;
4+
export default value;
5+
}
6+
7+
declare module "*.png" {
8+
const value: Uint8Array;
9+
export default value;
10+
}

assets/ruby.wasm

15.4 MB
Binary file not shown.

esbuild.config.mjs

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
import esbuild from "esbuild";
22
import process from "process";
33
import builtins from "builtin-modules";
4-
import { wasmLoader } from "esbuild-plugin-wasm";
54

65
const banner = `/*
76
THIS IS A GENERATED/BUNDLED FILE BY ESBUILD
@@ -12,6 +11,10 @@ if you want to view the source, please visit the github repository of this plugi
1211
const prod = process.argv[2] === "production";
1312

1413
const context = await esbuild.context({
14+
loader: {
15+
".wasm": "binary",
16+
".png": "binary",
17+
},
1518
banner: {
1619
js: banner,
1720
},
@@ -39,7 +42,7 @@ const context = await esbuild.context({
3942
sourcemap: prod ? false : "inline",
4043
treeShaking: true,
4144
outfile: "main.js",
42-
plugins: [wasmLoader()],
45+
plugins: [],
4346
});
4447

4548
if (prod) {

main.ts

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import { App, Editor, MarkdownView, Modal, Plugin } from "obsidian";
2-
32
import { DefaultRubyVM } from "@ruby/wasm-wasi/dist/browser";
3+
import rubyWASM from "./assets/ruby.wasm";
44

55
export default class RubyWasmPlugin extends Plugin {
66
// Function to check if inside code block
@@ -24,10 +24,7 @@ export default class RubyWasmPlugin extends Plugin {
2424
};
2525

2626
async onload() {
27-
const response = await fetch(
28-
"https://cdn.jsdelivr.net/npm/@ruby/[email protected]/dist/ruby+stdlib.wasm"
29-
);
30-
const module = await WebAssembly.compileStreaming(response);
27+
const module = await WebAssembly.compile(rubyWASM);
3128
const { vm } = await DefaultRubyVM(module);
3229

3330
// This adds a simple command that can be triggered anywhere

package-lock.json

Lines changed: 0 additions & 14 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,6 @@
1717
"@typescript-eslint/parser": "5.29.0",
1818
"builtin-modules": "3.3.0",
1919
"esbuild": "0.17.3",
20-
"esbuild-plugin-wasm": "^1.1.0",
2120
"obsidian": "latest",
2221
"tslib": "2.4.0",
2322
"typescript": "4.7.4"

0 commit comments

Comments
 (0)