Skip to content

Commit

Permalink
[js/web] allow import .mjs/.wasm file (#23487)
Browse files Browse the repository at this point in the history
### Description

Allow importing the `.mjs` and `.wasm` files.

when using Vite, this enables web app to consume ORT-web for simplify
the setup:
   ```js
   import * as ort from 'onnxruntime-web';

   import wasmFileUrl from 'onnxruntime-web/.wasm?url';
   ort.env.wasm.wasmPaths = { wasm: wasmFileUrl };
  • Loading branch information
fs-eire authored Jan 29, 2025
1 parent 655a23f commit bf023ab
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 1 deletion.
6 changes: 6 additions & 0 deletions js/web/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -77,16 +77,22 @@
"require": "./dist/ort.min.js",
"types": "./types.d.ts"
},
"./.mjs": "./dist/ort-wasm-simd-threaded.jsep.mjs",
"./.wasm": "./dist/ort-wasm-simd-threaded.jsep.wasm",
"./all": {
"import": "./dist/ort.all.bundle.min.mjs",
"require": "./dist/ort.all.min.js",
"types": "./types.d.ts"
},
"./all/.mjs": "./dist/ort-wasm-simd-threaded.jsep.mjs",
"./all/.wasm": "./dist/ort-wasm-simd-threaded.jsep.wasm",
"./wasm": {
"import": "./dist/ort.wasm.bundle.min.mjs",
"require": "./dist/ort.wasm.min.js",
"types": "./types.d.ts"
},
"./wasm/.mjs": "./dist/ort-wasm-simd-threaded.mjs",
"./wasm/.wasm": "./dist/ort-wasm-simd-threaded.wasm",
"./webgl": {
"import": "./dist/ort.webgl.min.mjs",
"require": "./dist/ort.webgl.min.js",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import * as ort from 'onnxruntime-web';
//
// see https://vite.dev/guide/assets.html#explicit-url-imports
//
import wasmFileUrl from '/node_modules/onnxruntime-web/dist/ort-wasm-simd-threaded.jsep.wasm?url';
import wasmFileUrl from 'onnxruntime-web/.wasm?url';

// wasmFileUrl is the URL of the wasm file. Vite will make sure it's available in both development and production.
ort.env.wasm.wasmPaths = { wasm: wasmFileUrl };
Expand Down

0 comments on commit bf023ab

Please sign in to comment.