Skip to content

[Feature]: Add as to raw import rules to reduce plugin exclusions #8870

Open

Description

@chenjiahan

What problem does this feature solve?

Rsbuild handles ?raw imports through dedicated oneOf branches in its JavaScript, CSS, asset, and preprocessor rules. Selecting a raw branch prevents other branches in the same oneOf from running, but the resource can still match subsequent independent compilation rules.

Plugins therefore need to repeat raw-query exclusions. For example, the Babel plugin's independent rule and the Solid refresh rule both exclude /[?&]raw(?:&|=|$)/.

Using Rspack's as option in raw branches could let subsequent extension-based compilation rules skip these resources automatically, reducing duplicated exclusions.

What does the proposed API look like?

Add as to existing raw branches, retaining their current query conditions and position within oneOf:

{
  resourceQuery: /[?&]raw(?:&|=|$)/,
  type: 'asset/source',
  as: '[resource-path].rsbuild-raw',
}

The suffix above is illustrative. For example, example.ts?raw would use example.ts.rsbuild-raw for subsequent path matching. A later rule matching TypeScript extensions would no longer select it, while the original file would still be read and exported as text.

Start with existing raw branches rather than introducing a global first-match raw rule. This preserves the current selection order and avoids unintentionally extending raw support to additional file types.

Compatibility and validation

  • Preserve each branch's existing query semantics and precedence relative to ?url, ?inline, ?worker, and import attributes.
  • Verify JavaScript/TypeScript, CSS, Sass/Less, JSON, and SVG raw imports in build and development, including Babel and refresh plugins.
  • Remove duplicated plugin exclusions only after confirming those rules run after the raw branch and are skipped by the rewritten path.
  • Check custom rules that intentionally process raw imports, since they may stop matching after the suffix is added.

as only changes nested and subsequent rule matching. It does not undo previously matched loaders, and rules based only on MIME types, query parameters, or other metadata can still match. The goal is to remove redundant exclusions where path matching provides equivalent behavior, not to guarantee that every plugin skips raw imports.

Related: #8869 evaluates the corresponding text/bytes import-attribute handling.

Activity

  1. added this to the 2.4.0 milestone on Nov 11, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions

      ⌂ 换网址