-
-
Notifications
You must be signed in to change notification settings - Fork 747
feat: add bytes support for asset modules #12548
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
Conversation
✅ Deploy Preview for rspack ready!
To edit notification comments on pull requests, go to your Netlify project configuration. |
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 pull request adds support for importing assets as Uint8Array using the bytes type in asset modules through the with { type: "bytes" } syntax, enhancing binary data handling capabilities similar to webpack's asset/source type.
Key changes:
- New
ToBinaryRuntimeModuleproviding platform-specific base64 decoding utilities for Node.js, Web, and Neutral platforms - New
asset/bytesmodule type with corresponding parser/generator support - Updated default module rules to recognize
with { type: "bytes" }imports
Reviewed changes
Copilot reviewed 13 out of 14 changed files in this pull request and generated 1 comment.
Show a summary per file
| File | Description |
|---|---|
crates/rspack_core/src/lib.rs |
Added AssetBytes module type enum variant and string conversion |
crates/rspack_core/src/runtime_globals.rs |
Added TO_BINARY runtime global (bit 69) and string rendering |
crates/rspack_plugin_asset/src/lib.rs |
Added bytes handling in asset parser/generator with base64 encoding for both JavaScript and CSS URL contexts |
crates/rspack_plugin_runtime/src/runtime_module/to_binary.rs |
New runtime module providing platform-specific base64-to-Uint8Array conversion |
crates/rspack_plugin_runtime/src/runtime_module/runtime/to_binary.ejs |
Runtime template with conditional Node.js Buffer or Web base64 decoder implementation |
crates/rspack_plugin_runtime/src/runtime_module/mod.rs |
Exported new ToBinaryRuntimeModule |
crates/rspack_plugin_runtime/src/runtime_plugin.rs |
Added runtime module injection for TO_BINARY requirement |
packages/rspack/src/config/defaults.ts |
Added default rule mapping with: { type: "bytes" } to asset/bytes |
packages/rspack/src/config/adapter.ts |
Added asset/bytes to generator options handling |
packages/rspack-test-tools/src/runner/node/index.ts |
Added TextDecoder to test globals |
tests/rspack-test/configCases/asset-modules/bytes/test.filter.js |
Removed TODO filter to enable bytes test |
tests/rspack-test/configCases/asset-modules/bytes/test.config.js |
Simplified CSS bundle reference |
tests/rspack-test/configCases/asset-modules/bytes/index.js |
Fixed expected CSS property value (removed leading space) |
tests/rspack-test/defaultsCases/default/base.js |
Updated test expectations to include new default bytes rule |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
Rsdoctor Bundle Diff AnalysisFound 5 projects in monorepo, 5 projects with changes. 📊 Quick Summary
📋 Detailed Reports (Click to expand)📁 react-10kPath:
📁 react-1kPath:
📁 react-5kPath:
📁 romePath:
📁 ui-componentsPath:
Generated by Rsdoctor GitHub Action |
📦 Binary Size-limit
❌ Size increased by 16.75KB from 47.88MB to 47.90MB (⬆️0.03%) |
CodSpeed Performance ReportMerging #12548 will not alter performanceComparing Summary
Footnotes
|
Summary
close #11881
This pull request adds support for the
bytestype in asset modules, allowing users to import assets asUint8Arraydirectly. This feature enables better handling of binary data in asset modules, similar to webpack's asset/source type but returning raw bytes instead of a string.The implementation includes:
ToBinaryRuntimeModulethat provides platform-specific base64 decoding utilitieswith { type: "bytes" }syntax in asset module importsThis change improves compatibility with webpack's asset module behavior and provides developers with more flexibility when working with binary assets.
Checklist