[js/web] allow import .mjs/.wasm file (#23487)

### 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 };
This commit is contained in:
Yulong Wang 2025-01-28 16:24:41 -08:00 committed by GitHub
parent 655a23ff1d
commit bf023ab3d5
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
2 changed files with 7 additions and 1 deletions

View file

@ -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",

View file

@ -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 };