rsbuild: [Bug]: resourceQuery not work in
System Info
System: OS: macOS 13.3 CPU: (10) arm64 Apple M2 Pro Memory: 90.48 MB / 16.00 GB Shell: 5.9 - /bin/zsh Binaries: Node: 20.12.2 - ~/.nvm/versions/node/v20.12.2/bin/node Yarn: 1.22.22 - ~/npm_global/bin/yarn npm: 10.5.0 - ~/.nvm/versions/node/v20.12.2/bin/npm pnpm: 8.6.3 - ~/npm_global/bin/pnpm bun: 1.1.4 - ~/npm_global/bin/bun Browsers: Chrome: 126.0.6478.185 Edge: 127.0.2651.74 Safari: 16.4
Details
I want to import a ts type file to use as a string, to inject typing to monaco editor
The following code will report an error
i have tried enforce:‘pre’ and config.module!.noParse = /myType.ts/; not work
// myType.ts
export type a = string;
// App.tsx
import str from "./myType.ts?raw";
console.log(str);
export default () => {
return <div>{str}</div>;
};
// rsbuild.config.ts
import { defineConfig } from "@rsbuild/core";
import { pluginReact } from "@rsbuild/plugin-react";
export default defineConfig({
plugins: [pluginReact()],
tools: {
rspack: (config, { addRules }) => {
addRules({
resourceQuery: /raw/,
type: "asset/source",
});
},
},
});
Reproduce link
No response
Reproduce Steps
just run code
About this issue
- Original URL
- State: closed
- Created 2 years ago
- Comments: 17 (4 by maintainers)
If you want to get the TypeScript source code instead of the transformed JavaScript code, you should exclude the assets with
?rawfrom the Rsbuild built-in TypeScript transformation rules.Yes, craco is not the same level I’ll try using only webpack to see if it supports raw feature like craco way
After testing, the result of webpack is consistent with rspack
webpack need configure attempt to match the rules in these arrays, and once the match is successful, no further rules will be attempted
maybe use oneOf to control the order of loaders
You may have confused a concept. CRACO and webpack are not tools of the same level. The demo you provided above is based on CRACO, not webpack.
Rspack / Rsbuild is compatible with webpack, not all upper-level tools based on webpack. We cannot make Rsbuild compatible with the behaviors of all different tools.
As for the
rawfeature, we plan to implement it in Rsbuild, but it significantly impacts the Rspack configuration within Rsbuild. We are still evaluating it.please try
import str from "!./myType.ts?raw";