mirror of
https://github.com/vercel/next.js.git
synced 2026-09-20 02:25:18 +08:00
7e9d7cbd60
### What?
Part of PACK-1007
Adds `condition.query` support to Turbopack's loader rules, enabling loaders to match based on import query strings (e.g., `import './file?raw'`). This mirrors webpack's `resourceQuery` functionality.
The `query` condition accepts either a string (exact match) or RegExp (pattern match).
Adds tests and documentation for the new `condition.query` option.
### How to use
```js
// next.config.js
module.exports = {
turbopack: {
rules: {
'*.txt': [
// String: exact match
{ condition: { query: '?raw' }, loaders: ['raw-loader'], as: '*.js' },
// RegExp: pattern match
{ condition: { query: /\?transform/ }, loaders: ['transform-loader'], as: '*.js' },
],
},
},
}
```
5 lines
138 B
JavaScript
5 lines
138 B
JavaScript
module.exports = function upperLoader(source) {
|
|
const upper = source.toUpperCase()
|
|
return `export default ${JSON.stringify(upper)}`
|
|
}
|