Upgrade to Pro
— share decks privately, control downloads, hide ads and more …
Speaker Deck
Sign up for free
Menu
Search
Features
All features
Private URLs
Password Protection
Custom URLS
Scheduled publishing
Remove Branding
Restrict embedding
Deck Collections
Notes
Features
All features
Private URLs
Password Protection
Custom URLS
Scheduled publishing
Remove Branding
Restrict embedding
Deck Collections
Notes
Explore
Featured decks
Featured speakers
Programming
Technology
Storyboards
Explore
Featured decks
Featured speakers
Programming
Technology
Storyboards
Pricing
Search
Sign in
Sign up for free
Vite + Rust で Wasm を ES Modulesとして使う
Search
hacusk
October 18, 2026
Programming
25
0
Share
Embed
Copy iframe code
Copy JS code
Copy link
Start on current slide
Vite + Rust で Wasm を ES Modulesとして使う
千歳ゆるい勉強会vol.8にて発表した内容です
hacusk
October 18, 2026
More Decks by hacusk
See All by hacusk
解剖"React Native"
hacusk
0
220
DuckDB-Wasmを使って ブラウザ上でRDBMSを動かす
hacusk
1
650
バックエンドの技術をブラウザで動かす技術
hacusk
0
140
形なしからの脱却
hacusk
0
41
Other Decks in Programming
See All in Programming
조합이폭발하는디자인시스템이걸눈으로도테스트하라고요
giljongyu
0
710
複数ドメインを一つのアプリに統合するFlutterの設計と運用_FlutterKaigi2026登壇資料(須永高弘)
takahirosunaga
0
140
Augmenting AI with the Power of Jakarta EE
ivargrimstad
0
570
Apple Intelligenceとオンデバイス時代の到来
yahir0
0
200
[DroidKnights 2026] Workflow AX: From Auto-Documented Policies to E2E Testing
raeminkang
0
510
Next.js: The final boss of Web Performance
guaca
0
380
AI-Powered Domain-Driven Design
ziobrando
0
380
[JA] Domain Modeling with Vanilla Rails: 「操作」から再考するRailsの設計論
yasaichi
4
1.8k
オーケストレーション記述言語 Katari
yukikurage
0
220
AWS CDKを理解するために公式の定義を深掘って解説してみる / Understanding AWS CDK by Digging into Its Official Definition
akihisaikeda
2
200
AIが実装を担う時代の「技術設計」と「チームマネジメント」
kamina_zzz
1
130
Long Living Tokens, Die, Die, Die! (or: The One Ring is Banned in Modern)
sylph01
0
400
Featured
See All Featured
The B2B funnel & how to create a winning content strategy
katarinadahlin
PRO
1
600
Designing for Timeless Needs
cassininazir
1
550
Effective software design: The role of men in debugging patriarchy in IT @ Voxxed Days AMS
baasie
1
600
Ethics towards AI in product and experience design
skipperchong
2
460
The Web Performance Landscape in 2024 [PerfNow 2024]
tammyeverts
12
1.4k
GraphQLの誤解/rethinking-graphql
sonatard
75
12k
職位にかかわらず全員がリーダーシップを発揮するチーム作り / Building a team where everyone can demonstrate leadership regardless of position
madoxten
70
68k
Claude Code のすすめ
schroneko
67
230k
Introduction to Domain-Driven Design and Collaborative software design
baasie
1
1.1k
Practical Tips for Bootstrapping Information Extraction Pipelines
honnibal
25
2.2k
SEO Brein meetup: CTRL+C is not how to scale international SEO
lindahogenes
2
3k
The #1 spot is gone: here's how to win anyway
tamaranovitovic
4
1.2k
Transcript
Vite + Rust で Wasm を ES Modulesとして 使う import
{ add } from './main.wasm' HakataYusuke(@hacusk) 千歳ゆるい勉強会 vol.8 2026.10.18(Sun.) @公立千歳科学技術大学 1
$ whoami Name: はくすけ(@hacusk) / HakataYusuke Job: 株式会社モニクル SWE Language:TypeScript,
Go, PHP… FavoriteTech: MultiPlatformなもの, OSS, ネ ットワーク Love: 声優, 旅行, ライブ, アイドル, 車, モータ ースポーツ, ガジェット, 飛行機, 麻雀 Community: 函館本線沿線勉強会, フロントエ ンドカンファレンス北海道実行委員会, OSC北 海道実行委員会, 一般社団法人LOCAL Website: https://hacusk.net/ 2
WebAssembly(Wasm)ってなに? 普通のコンパイル C / Rust / Go → その CPU
向けの機械語 x86 用バイナリは ARM では動かない OS・アーキテクチャに依存する Wasm → 仮想マシン向けのバイナリ ブラウザ(や WASI)が実行してくれる 一度作れば、環境が違っても同じファイル が動く JVM(Java のバイトコード)に近い発想。 違いは、最初から Web ブラウザで速く・安全に動かすことを狙って設計されている点(W3C 標準)。 3
なにがうれしいの? JavaScript 以外の言語(Rust, Go, C/C++ …)のコードをブラウザで動かせる ネイティブに近い速さで計算できる(画像処理・圧縮・数値計算など) 主要ブラウザすべてで動く 4
Wasm をブラウザで使う従来の方法 const res = await fetch('./add.wasm') const { instance
} = await WebAssembly.instantiateStreaming(res) const add = instance.exports.add 手動でフェッチ・インスタンス化が必要 普通の JS インポートとまったく異なる体験 5
Vite の Wasm サポート — 2 段階 アプローチ 構文 特徴
?init import init from './add.wasm?init' init 関数を呼び、exports を取り出す ESM 統合 import { add } from './add.wasm' 通常の named import と同じ ESM 統合は WebAssembly/ES Module Integration 提案 に準拠 Vite 8.1〜 コアでサポート(追加プラグイン不要) 6
言語の選択 — TinyGo vs Rust TinyGo Rust ( wasm32-unknown-unknown )
500 B 不要 ゼロ Wasm サイズ 21 KB JS ランタイム wasm_exec.js 必須 Wasm imports go.* 多数 ?init 呼び出し await init(go.importObject) await init() Rust はランタイムを含まない 純粋な Wasm を出力 → ESM 統合と相性が良い 7
Rust 側のコード // wasm/src/lib.rs #[unsafe(no_mangle)] // edition 2024 では unsafe
が必要 pub fn add(a: i32, b: i32) -> i32 { a + b } #[unsafe(no_mangle)] pub fn fibonacci(n: u32) -> u64 { /* ... */ } // → JS では BigInt # Cargo.toml [lib] crate-type = ["cdylib"] # C 互換の動的ライブラリとして出力 8
Vue コンポーネントでの使用 <script setup lang="ts"> import { add, fibonacci }
from '../assets/main.wasm' // 非同期モジュール — 親で <Suspense> が必要 </script> <template> <output>{{ add(3, 4) }}</output> </template> 普通の JS モジュールと 完全に同じ感覚 でインポートできる 9
デモ 10
ハマりどころ(Vite 8.1+) 型は手書き .d.wasm.ts + allowArbitraryExtensions // main.d.wasm.ts export declare
function add(a: number, b: number): number 出典: Vite — ESM 統合 / TSConfig — allowArbitraryExtensions 非同期モジュール は TLA 相当の async module → Vue では親に <Suspense> .wasm <Suspense> <WasmDemo /> </Suspense> 出典: Vite — ESM 統合 11
まとめ Rust (edition 2024) └─ cargo wasm └─ main.wasm (500B、imports
ゼロ) └─ Vite 8.1+(コアの ESM 統合) └─ import { add } from './main.wasm' └─ Vue コンポーネントで直接呼び出し Rust × wasm32-unknown-unknown が ESM 統合に最も相性が良い Vite 8.1〜 は import { add } from './x.wasm' が標準サポート 型は .d.wasm.ts + allowArbitraryExtensions で解決 コード: https://github.com/hacusk/vite-wasm-esm-integration-example 12
告知 13
Sapporo.sre #1 2026.11.19(Thu.) @北海道ガス株式会社 本社ビル(札幌市) https://sapporo-sre.connpass.com/event/401691/ 14
TechRAMEN 2026 Conference 2026.11.20(Fri.)〜21(Sat.) @コンシェルジュ フラノ https://techramenconf.net/2026/ 15
LOCAL Developer Day '26 in EBETSU 2026.12.19(Sat.) @北海道情報大学 eDCタワー 10F(江別市)
https://www.local.or.jp/2026/09/10111.html 16