Skip to content

Conversation

@LingyuCoder
Copy link
Contributor

@LingyuCoder LingyuCoder commented Dec 24, 2025

Summary

close #11881

This pull request adds support for the bytes type in asset modules, allowing users to import assets as Uint8Array directly. 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:

  • A new ToBinaryRuntimeModule that provides platform-specific base64 decoding utilities
  • Support for with { type: "bytes" } syntax in asset module imports
  • Proper handling across different platforms (Node.js, Web, and Neutral)

This change improves compatibility with webpack's asset module behavior and provides developers with more flexibility when working with binary assets.

Checklist

  • Tests updated (or not required).
  • Documentation updated (or not required).

Copilot AI review requested due to automatic review settings December 24, 2025 05:17
@netlify
Copy link

netlify bot commented Dec 24, 2025

Deploy Preview for rspack ready!

Name Link
🔨 Latest commit 1735e52
🔍 Latest deploy log https://app.netlify.com/projects/rspack/deploys/694b8df84f4da70008b5ff5a
😎 Deploy Preview https://deploy-preview-12548--rspack.netlify.app
📱 Preview on mobile
Toggle QR Code...

QR Code

Use your smartphone camera to open QR code link.

To edit notification comments on pull requests, go to your Netlify project configuration.

@github-actions github-actions bot added release: feature release: feature related release(mr only) team The issue/pr is created by the member of Rspack. labels Dec 24, 2025
Copy link
Contributor

Copilot AI left a 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 ToBinaryRuntimeModule providing platform-specific base64 decoding utilities for Node.js, Web, and Neutral platforms
  • New asset/bytes module 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.

@github-actions
Copy link
Contributor

github-actions bot commented Dec 24, 2025

Rsdoctor Bundle Diff Analysis

Found 5 projects in monorepo, 5 projects with changes.

📊 Quick Summary
Project Total Size Change
react-10k 5.7 MB -
react-1k 823.4 KB -
react-5k 2.7 MB -
rome 984.3 KB -
ui-components 2.1 MB -
📋 Detailed Reports (Click to expand)

📁 react-10k

Path: ../build-tools-performance/cases/react-10k/dist/rsdoctor-data.json

⚠️ No baseline data found - Unable to perform comparison analysis

Metric Current Baseline Change
📊 Total Size 5.7 MB - -
📄 JavaScript 5.7 MB - -
🎨 CSS 21.0 B - -
🌐 HTML 0 B - -
📁 Other Assets 0 B - -

📁 react-1k

Path: ../build-tools-performance/cases/react-1k/dist/rsdoctor-data.json

⚠️ No baseline data found - Unable to perform comparison analysis

Metric Current Baseline Change
📊 Total Size 823.4 KB - -
📄 JavaScript 823.4 KB - -
🎨 CSS 0 B - -
🌐 HTML 0 B - -
📁 Other Assets 0 B - -

📁 react-5k

Path: ../build-tools-performance/cases/react-5k/dist/rsdoctor-data.json

⚠️ No baseline data found - Unable to perform comparison analysis

Metric Current Baseline Change
📊 Total Size 2.7 MB - -
📄 JavaScript 2.7 MB - -
🎨 CSS 21.0 B - -
🌐 HTML 0 B - -
📁 Other Assets 0 B - -

📁 rome

Path: ../build-tools-performance/cases/rome/dist/rsdoctor-data.json

⚠️ No baseline data found - Unable to perform comparison analysis

Metric Current Baseline Change
📊 Total Size 984.3 KB - -
📄 JavaScript 984.3 KB - -
🎨 CSS 0 B - -
🌐 HTML 0 B - -
📁 Other Assets 0 B - -

📁 ui-components

Path: ../build-tools-performance/cases/ui-components/dist/rsdoctor-data.json

⚠️ No baseline data found - Unable to perform comparison analysis

Metric Current Baseline Change
📊 Total Size 2.1 MB - -
📄 JavaScript 2.0 MB - -
🎨 CSS 83.0 KB - -
🌐 HTML 0 B - -
📁 Other Assets 0 B - -

Generated by Rsdoctor GitHub Action

@github-actions
Copy link
Contributor

github-actions bot commented Dec 24, 2025

📦 Binary Size-limit

Comparing 1735e52 to chore(deps): update patch npm dependencies (#12543) by renovate[bot]

❌ Size increased by 16.75KB from 47.88MB to 47.90MB (⬆️0.03%)

@codspeed-hq
Copy link

codspeed-hq bot commented Dec 24, 2025

CodSpeed Performance Report

Merging #12548 will not alter performance

Comparing feat/asset-modules-bytes-support (1735e52) with main (30890a5)1

Summary

✅ 16 untouched
⏩ 1 skipped2

Footnotes

  1. No successful run was found on main (2e2784a) during the generation of this report, so 30890a5 was used instead as the comparison base. There might be some changes unrelated to this pull request in this report.

  2. 1 benchmark was skipped, so the baseline result was used instead. If it was deleted from the codebase, click here and archive it to remove it from the performance reports.

@LingyuCoder LingyuCoder enabled auto-merge (squash) December 24, 2025 07:00
@LingyuCoder LingyuCoder merged commit 0866596 into main Dec 24, 2025
80 of 82 checks passed
@LingyuCoder LingyuCoder deleted the feat/asset-modules-bytes-support branch December 24, 2025 07:38
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

release: feature release: feature related release(mr only) team The issue/pr is created by the member of Rspack.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Feature]: Support with { type: 'bytes' } imports

3 participants