Repository navigation
feat(wasm): direct .wasm imports (WASM ESM Integration) - #21779
Merged
Merged
Conversation
Add support for importing .wasm files directly without the ?init suffix. The plugin parses wasm binary to extract imports/exports, generates appropriate glue code, and handles both dev and SSR build modes.
Contributor
Author
|
|
it's no longer needed as `.wasm` is now handled
sapphi-red
approved these changes
Jun 2, 2026
sapphi-red
left a comment
Member
There was a problem hiding this comment.
Thanks!
I added some changes:
- removed wasm-fallback plugin: it's no longer needed as
.wasmis now handled - added docs for this new feature
@vitejs/plugin-legacy
vite
commit: |
This was referenced Jun 13, 2026
graphite-app Bot
pushed a commit
to rolldown/rolldown
that referenced
this pull request
Jun 15, 2026
Remove `rolldown_plugin_vite_wasm_fallback` because it is not used after vitejs/vite#21779.
4 of 5 tasks
mho22
added a commit
to WordPress/wordpress-playground
that referenced
this pull request
Sep 30, 2026
## Motivation for the change, related issues
Every `@php-wasm/web` loader declares `dependencyFilename` with a bare
import of a `.wasm` file, which relies on the bundler treating it as an
asset. Vite 8 implements the WASM ESM Integration proposal and resolves
it as a module instead, so the build fails with `[MISSING_EXPORT]
"default" is not exported`. `assetsInclude` does not apply, so there is
no opt-out. This PR switches the web loaders to `new
URL('./php_X_Y.wasm', import.meta.url).href`, the form #3692 already
ships for the PHP next loaders.
## Implementation details
- **Loaders:** `Dockerfile` and `Dockerfile-5-2` emit the new line for
web builds; the Node branch keeps `path.join()`. The 16 committed
loaders get the same rewrite, so the published packages need no
recompile.
- **Breaking:** The loaders now use `import.meta`, so bundling
`@php-wasm/web` to `cjs` or `iife` throws `TypeError: Invalid URL` at
load. The published packages are unaffected — `index.cjs` keeps a native
dynamic `import()`. webpack 5 users must drop any `.wasm` `file-loader`
rule.
- **Vite configs:** The dead `wasm` entry goes from `viteIgnoreImports`
in six configs. `playground-website` and `playground-personal-wp` mark
`/^@php-wasm\/web-\d+-\d+$/` external, since neither calls
`loadWebRuntime()`.
- **Bundler tests:** Vite lib mode always inlines a `new URL()` asset as
base64, because `shouldInline()` returns early on `config.build.lib`.
Externalizing the version packages takes the web bundle from 617 MB to
817 KB.
- **Guards:** `loader-wasm-url.spec.ts` asserts all 16 loaders declare
`new URL()`; `run-bundler-tests` fails on a base64 WASM data URI. The
dead esbuild `loader` key goes too, leaving built artifacts
byte-identical.
## Testing Instructions (or ideally a Blueprint)
- [x] `npx nx test php-wasm-web` — 76 pass, 16 of them in
`loader-wasm-url.spec.ts`
- [x] Built a committed loader with Vite 8.3.1 — the bare import fails,
`new URL()` builds
- [x] Booted 8 PHP versions × jspi/asyncify on the dev server (16/16, no
console errors)
- [x] `playground-website` and `playground-personal-wp` build with 0
`.wasm` files, down from 16
- [ ] Confirm no consumer needs a `cjs` or `iife` bundle of the web
runtime
See: vitejs/vite#21779
<!-- This is an auto-generated comment: release notes by coderabbit.ai
-->
## Summary by CodeRabbit
* **Bug Fixes**
* Improved WebAssembly loading across supported PHP versions by
resolving binaries relative to their modules.
* Updated web build configurations to keep PHP binaries from being
embedded as large base64 data.
* **Documentation**
* Updated bundler setup guidance with asset-serving requirements and
configuration notes.
* **Tests**
* Added checks for WebAssembly URL resolution and for unexpectedly
embedded binaries in web bundles.
<!-- end of auto-generated comment: release notes by coderabbit.ai -->
Co-authored-by: Claude Opus 5 (1M context) <noreply@anthropic.com>
tomio2480
added a commit
to tomio2480/frontend-phpcon-do-2026
that referenced
this pull request
Nov 26, 2026
…を塞ぐ (#126) vite の repository advisory GHSA-p4f5-76q4-ffq7(Critical)の範囲から外すためである. dev server へ細工した要求を送ると,サーバー上で任意のコードを実行できる. server.fs の許可外にあるファイルも読み出せる. 影響を受けるのは,--host や server.host で dev server をネットワークへ公開した場合である. GHSA-p4f5-76q4-ffq7 対象は 8.0.0〜8.1.6・8.2.0〜8.2.4・8.3.0〜8.3.6 で,修正版は 8.1.7・8.2.5・8.3.7 である. main の 8.0.16 は範囲内にある.global の Advisory Database には未登録のため, Dependabot alert と pnpm audit には現れない. 脆弱なコードは Rolldown のバイナリ側にあり,8.3.7 以降は Rolldown 1.2.17 の修正に依る. 8.3.8 は rolldown ~1.2.18 を要求し,lock は 1.2.19 を解決する. Dependabot の #119 は 8.1.6 止まりで修正版に届かないため,本変更で置き換える. 8.x 系の最新である 8.3.8 を採る.8.0.16 が範囲内にある次の advisory からも外れる. - GHSA-587h-7wmj-h5pm(High,launch-editor の存在確認の迂回,Windows) - GHSA-698v-4r3x-3vcv(Moderate,launch-editor の % エスケープ漏れ,Windows) - GHSA-r825-w8mm-5pxw(Moderate,launch-editor の CLI フラグ誤解釈) - GHSA-rq7h-c2jc-7f22(Moderate,server.fs.allow 外のファイル配信) - GHSA-9jrq-w75r-8gcw(Low,カスタムミドルウェア経由のクロスオリジン実行) vite が引く postcss 8.5.33・nanoid 3.3.20 により,両者の advisory 4 件も外れる. pnpm audit は low 1・moderate 8・high 8 から moderate 4・high 4 に減る. vite 8.1 以降は .wasm の素の import を WASM ESM Integration として解決する(vitejs/vite#21779). assetsInclude は効かず,default import が「MISSING_EXPORT」で build を止める. @php-wasm 3.1.56 以前のローダーはこの形で .wasm を読むため,8.1 以降と組めない. #119 が基点とする 877fa4e の @php-wasm 3.1.48・3.1.49 はこれに当たる. @php-wasm 3.1.57 で new URL(..., import.meta.url) の形へ変わった(WordPress/wordpress-playground#4347). main は #117 で 3.1.66 へ上がっているため,vite.config.ts の手当ては要らない. pnpm-lock.yaml の差分は vite の依存の部分木に限られる. rolldown・@rolldown/binding-*・@oxc-project/types・postcss・nanoid・source-map-js・picomatch, rolldown の wasm32-wasi 用バインディングが引く @emnapi・@napi-rs/wasm-runtime・@tybys/wasm-util が入れ替わる. vite を peer に持つ preset-vite・tailwindcss/vite・vitest などは,参照先の版だけが変わる. lightningcss は @tailwindcss/node が 1.32.0 を完全一致で要求し,vite は ^1.33.0 を要求する. このため 1.33.0 が並んで入り,lock の cpu・os・libc 行がそれぞれ 12・12・4 行増える. 増分は lightningcss 1.33.0 の 11 パッケージと @rolldown/binding-android-arm-eabi の分である. 既存の行は 1 行も減らない. main(#114 のマージ後.木は検証時の基点 1c63775 と同一)を基点に, Windows(Node.js 26.13.1・pnpm 11.5.0)で次を確認した. - CI=true で node_modules を消してから pnpm install --frozen-lockfile が成功し, pnpm-lock.yaml・package.json・pnpm-workspace.yaml が書き換わらない - pnpm test: 13 files / 128 tests 成功 - pnpm run test:coverage 成功(カバレッジ値は main と同一) - pnpm build(tsc -b && vite build)成功.dist は main の 87 ファイルに 1 ファイル加わる. .wasm・.so・icu.dat・public 由来のファイルなど 59 ファイルは main と同一である. JS チャンクは Rolldown の出力変化で作り直され,共通の rolldown-runtime チャンクが加わる. CSS は rounded-full の無限大の表記だけが変わり,index.html は内部の style が圧縮される - vite preview と dev server の両方で,市町村を選ぶと 4 指標の集計が表示される. JSPI 版と asyncify 版のどちらのローダーでも PHP の初期化が成功する - dev server の __vite-browser-external は,受け取った ID を文字列リテラルへエスケープして埋め込む - lock で追加した 39 パッケージの integrity は npm レジストリの値と一致する Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Add support for importing
.wasmfiles directly without the?initsuffix, by the WASM ESM Integration draft standard. The plugin parses wasm binary to extract imports/exports, generates appropriate glue code, and handles both dev and SSR build modes.close #4551