Skip to content

Commit 78d91cd

Browse files
authoredMar 24, 2025
[js/web] allow bundler import condition for not bundling wasm (#24014)
### Description <!-- Describe your changes. --> This gives a way for webapp developers to customize the bundler behavior regarding whether to bundle the wasm. To avoid treating ort-wasm-threaded-simd.jsep.mjs and ort-wasm-threaded-simd.jsep.wasm as dependencies during the process of bundler build, use import condition `onnxruntime-web-use-extern-wasm`. For webpack: ``` module.exports = { //... resolve: { conditionNames: ['onnxruntime-web-use-extern-wasm', 'import', 'module'], }, }; ``` For esbuild: ``` await esbuild.build({ //... conditions: ['onnxruntime-web-use-extern-wasm', 'import', 'module'], }) ``` For rollup: ``` import { nodeResolve } from '@rollup/plugin-node-resolve'; export default { //... plugins: [nodeResolve({ exportConditions: ['onnxruntime-web-use-extern-wasm', 'import', 'module', 'development|production'] })] }; ``` ### Motivation and Context <!-- - Why is this change required? What problem does it solve? - If it fixes an open issue, please link to the issue here. --> - #24009
1 parent e03631e commit 78d91cd

File tree

1 file changed

+16
-4
lines changed

1 file changed

+16
-4
lines changed
 

‎js/web/package.json

+16-4
Original file line numberDiff line numberDiff line change
@@ -72,23 +72,35 @@
7272
"import": "./dist/ort.node.min.mjs",
7373
"require": "./dist/ort.node.min.js"
7474
},
75-
"import": "./dist/ort.bundle.min.mjs",
75+
"import": {
76+
"onnxruntime-web-use-extern-wasm": "./dist/ort.min.mjs",
77+
"default": "./dist/ort.bundle.min.mjs"
78+
},
7679
"require": "./dist/ort.min.js"
7780
},
7881
"./all": {
79-
"import": "./dist/ort.all.bundle.min.mjs",
82+
"import": {
83+
"onnxruntime-web-use-extern-wasm": "./dist/ort.all.min.mjs",
84+
"default": "./dist/ort.all.bundle.min.mjs"
85+
},
8086
"require": "./dist/ort.all.min.js"
8187
},
8288
"./wasm": {
83-
"import": "./dist/ort.wasm.bundle.min.mjs",
89+
"import": {
90+
"onnxruntime-web-use-extern-wasm": "./dist/ort.wasm.min.mjs",
91+
"default": "./dist/ort.wasm.bundle.min.mjs"
92+
},
8493
"require": "./dist/ort.wasm.min.js"
8594
},
8695
"./webgl": {
8796
"import": "./dist/ort.webgl.min.mjs",
8897
"require": "./dist/ort.webgl.min.js"
8998
},
9099
"./webgpu": {
91-
"import": "./dist/ort.webgpu.bundle.min.mjs",
100+
"import": {
101+
"onnxruntime-web-use-extern-wasm": "./dist/ort.webgpu.min.mjs",
102+
"default": "./dist/ort.webgpu.bundle.min.mjs"
103+
},
92104
"require": "./dist/ort.webgpu.min.js"
93105
}
94106
},

0 commit comments

Comments
 (0)