Skip to content

Conversation

@chenjiahan
Copy link
Member

Summary

Add support for importing the raw content of JavaScript, TypeScript, and JSX files through the ?raw query parameter. This makes the ?raw query more general and intuitive.

import rawJs from './script1.js?raw';
import rawTs from './script2.ts?raw';
import rawJsx from './script3.jsx?raw';
import rawTsx from './script4.tsx?raw';

console.log(rawJs); // The raw content of the JS file
console.log(rawTs); // The raw content of the TS file
console.log(rawJsx); // The raw content of the JSX file
console.log(rawTsx); // The raw content of the TSX file

Related Links

#2665

Checklist

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

Copilot AI review requested due to automatic review settings June 3, 2025 14:23
@netlify
Copy link

netlify bot commented Jun 3, 2025

Deploy Preview for rsbuild ready!

Name Link
🔨 Latest commit 3e169b3
🔍 Latest deploy log https://app.netlify.com/projects/rsbuild/deploys/683fb2447fbbd80008744b13
😎 Deploy Preview https://deploy-preview-5353--rsbuild.netlify.app
📱 Preview on mobile
Toggle QR Code...

QR Code

Use your smartphone camera to open QR code link.
Lighthouse
Lighthouse
1 paths audited
Performance: 72 (🟢 up 10 from production)
Accessibility: 97 (no change from production)
Best Practices: 92 (no change from production)
SEO: 100 (no change from production)
PWA: 60 (no change from production)
View the detailed breakdown and full score reports

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

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 PR introduces support for importing the raw content of JavaScript, TypeScript, JSX, and TSX files via the “?raw” query parameter.

  • Updated various module rules across plugins (svelte, react, babel, swc, and webpack) to conditionally handle raw imports.
  • Added a new rule in the SWC plugin to treat “?raw” imports as asset/source.

Reviewed Changes

Copilot reviewed 15 out of 15 changed files in this pull request and generated no comments.

Show a summary per file
File Description
packages/plugin-svelte/tests/snapshots/index.test.ts.snap Added "resourceQuery" rule for non‐raw/inline JS/TS files.
packages/plugin-react/tests/snapshots/index.test.ts.snap Updated snapshot to exclude raw files from standard JS processing.
packages/plugin-babel/tests/snapshots/index.test.ts.snap Included "resourceQuery" checks to filter raw imports.
packages/core/tests/snapshots/swc.test.ts.snap Added raw asset rule snapshots for SWC plugin.
packages/core/src/plugins/swc.ts Introduced a new rule for handling “?raw” imports using asset/source type.
packages/core/src/configChain.ts Added a new constant for the raw JS rule.
packages/compat/webpack/tests/snapshots/default.test.ts.snap Updated webpack snapshots with raw content handling.
e2e/cases/assets/raw-query/* Added tests and sample files to verify raw asset loading functionality.

@chenjiahan chenjiahan merged commit efd7b76 into main Jun 4, 2025
11 checks passed
@chenjiahan chenjiahan deleted the script_raw_0603 branch June 4, 2025 02:48
@nanianlisao
Copy link
Contributor

@chenjiahan

Why not make the distinction directly through oneOf but add an independent rule instead?

I think it should be consistent with the scope of the default rules, for example, also affected by source.include. Moreover, using oneOf seems even easier to understand.

Are there any other reasons?

@chenjiahan
Copy link
Member Author

Switch to oneOf is a breaking change, as it changed the rule structure

@chenjiahan
Copy link
Member Author

I'm considering using oneOf in Rsbuild v2. Thank you for your feedback!

@nanianlisao
Copy link
Contributor

I'm considering using oneOf in Rsbuild v2. Thank you for your feedback!

hah, I was just about to ask if I was considering applying it in 2.0

@chenjiahan
Copy link
Member Author

Updated in: #7032

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants