Skip to content

[Web] No way to prevent the default wasm from being bundled #24009

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
Eldow opened this issue Mar 12, 2025 · 1 comment
Open

[Web] No way to prevent the default wasm from being bundled #24009

Eldow opened this issue Mar 12, 2025 · 1 comment
Labels
api:Javascript issues related to the Javascript API platform:web issues related to ONNX Runtime web; typically submitted using template stale issues that have not been addressed in a while; categorized by a bot

Comments

@Eldow
Copy link

Eldow commented Mar 12, 2025

Describe the issue

Hello 👋

Thank you for this great library,

We are facing an issue when specifying custom wasm paths:

ort.env.wasm.wasmPaths = {
  wasm: chrome.runtime.getURL("./test.wasm"),
  mjs: chrome.runtime.getURL("./test.mjs")
};

Then as an application build process, we added a specific build step to output the custom wasm binary and corresponding mjs file into the destination directory.

When running webpack, the bundled output still contains the 10.5MB default wasm (first file in the picture below) shipped with onnxruntime-web and is still referenced in the bundled javascript (second picture).

This increases the size of our extension artifact unnecessarily, that can be consequential and could come as a surprise.

Image Image

Is there a way to properly exclude the default wasm from the bundle when providing a custom one ?

Thank you !

To reproduce

Reproduction sandbox - run pnpm build to generate a new folder in ./dist :
https://codesandbox.io/p/devbox/s4mxt9
In the dist folder, you can see the generated WASM asset and the reference to it in the main.js file.

Urgency

We have a non-ideal workaround in place by not relying on wasmPaths and replacing the default wasm/mjs files directly in the library after building it following the official documentation. Solving this issue would allow us to get rid of this custom integration.

ONNX Runtime Installation

Released Package

ONNX Runtime Version or Commit ID

1.19.2

Execution Provider

'wasm'/'cpu' (WebAssembly CPU)

@Eldow Eldow added the platform:web issues related to ONNX Runtime web; typically submitted using template label Mar 12, 2025
@github-actions github-actions bot added the api:Javascript issues related to the Javascript API label Mar 12, 2025
fs-eire added a commit that referenced this issue Mar 24, 2025
### 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
Copy link
Contributor

This issue has been automatically marked as stale due to inactivity and will be closed in 30 days if no further activity occurs. If further support is needed, please provide an update and/or more details.

@github-actions github-actions bot added the stale issues that have not been addressed in a while; categorized by a bot label Apr 12, 2025
quic-zhaoxul pushed a commit to CodeLinaro/onnxruntime that referenced this issue Apr 17, 2025
…oft#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. -->

- microsoft#24009
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
api:Javascript issues related to the Javascript API platform:web issues related to ONNX Runtime web; typically submitted using template stale issues that have not been addressed in a while; categorized by a bot
Projects
None yet
Development

No branches or pull requests

1 participant