-
Notifications
You must be signed in to change notification settings - Fork 19
perf: use url to replace wasm module import #479
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
base: main
Are you sure you want to change the base?
Conversation
|
|
💖 Thanks for opening this pull request! 💖 Please follow the contributing guidelines. And we use [semantic commit messages to streamline the release process. Examples of commit messages with semantic prefixes:
Things that will help get your PR across the finish line:
Please be patient and we will get back to you as soon as we can. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Pull request overview
This PR replaces the module-based WASM import with a URL-based approach to improve bundle size and build speed. Instead of importing the WASM file as a module, it now fetches the oniguruma WASM file directly from unpkg.com CDN.
- Removes the module import of
vscode-oniguruma/release/onig.wasm - Uses a direct CDN URL to fetch the WASM file at runtime
- Simplifies the URL handling logic by removing conditional checks for different path formats
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
| onigurumaUrl = onigurumaPath.default; | ||
| } | ||
| const onigurumaPath = 'https://unpkg.com/vscode-oniguruma@2.0.1/release/onig.wasm'; | ||
| const url = new URL(onigurumaPath); |
Copilot
AI
Dec 14, 2025
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Creating a URL object from an absolute URL string is unnecessary overhead. The fetch() API accepts strings directly, so you can pass 'onigurumaPath' to fetch without wrapping it in a URL object first.
| if (typeof onigurumaPath !== 'string' && onigurumaPath.default) { | ||
| onigurumaUrl = onigurumaPath.default; | ||
| } | ||
| const onigurumaPath = 'https://unpkg.com/vscode-oniguruma@2.0.1/release/onig.wasm'; |
Copilot
AI
Dec 14, 2025
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Using a hardcoded external CDN URL (unpkg.com) may cause reliability issues in environments with restricted network access, offline scenarios, or if the CDN is unavailable. Consider making this URL configurable through an environment variable or configuration file, or bundling the WASM file as a fallback option.
使用
new URL('')来替代 module import 去导入 wasm 产物,这样可以避免产物的 bundle 的体积 & 构建速度。用 webpack 测试过,看上去使用上效果都是一样的。