How to use resourceQuery loader options with turbopack? #65360
-
SummaryWe recently migrated a big project to the latest version of Next and wanted to try out turbopack. The project loads faster with it so it feels good on this front. However, there is still one issue that blocks us from migrating completely to turbopack. We have special configuration for With webpack, this configuration is done with: Webpack configurationwebpack: (config) => {
// use default url loader when importing SVG with "*.svg?url"
config.module.rules.push({
test: /\.svg$/i,
type: "asset",
resourceQuery: /url/,
});
config.module.rules.push({
test: /\.svg$/i,
issuer: /\.tsx?$/,
resourceQuery: { not: [/url/] }, // only if not *.svg?url
use: [
{
loader: "@svgr/webpack",
options: {
icon: true,
svgProps: { role: "img", "aria-label": "" },
},
},
],
});
return config;
},I did not find a way of doing it with turbo. This is the configuration I have for my icons but I can't add the Turbo configurationturbo: {
rules: {
"*.svg": {
loaders: [
{
loader: "@svgr/webpack",
options: {
icon: true,
svgProps: { role: "img", "aria-label": "" },
},
},
],
as: "*.js",
},
},
},Do you know if this is currently feasible with turbopack? Thank you Additional informationNo response ExampleNo response |
Beta Was this translation helpful? Give feedback.
Replies: 2 comments 10 replies
-
|
@clement-escolano have you managed to find a solution for your issue? I need to achieve the same and I'm kinda blocked as well. |
Beta Was this translation helpful? Give feedback.
-
|
Hi, Currently, Turbopack does not fully support all the loader-specific query options available in Webpack, including the Recommended approaches:
This approach ensures a clear separation between icons and image SVGs while maintaining compatibility with Turbopack’s current capabilities. |
Beta Was this translation helpful? Give feedback.
Next.js 16 shipped Turbopack condition rules, which allow loaders to be applied conditionally.
For example, you can use the
pathcondition to apply SVGR only to theiconsfolder while keeping the default loader for all other SVGs:The only challenge is typings: TypeScript is not aware of Turbopack rules, so an imported
.svgfile might be treated either as a React component or as a static image{ src, width, height }.In my projects, I replaced SVGR with inlining icons as data URIs. It’s more performant and also solves the typing iss…