mirror of
https://github.com/hanzoai/next.js.git
synced 2026-09-24 17:00:51 +00:00
### 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' },
],
},
},
}
```
29 lines
740 B
JavaScript
29 lines
740 B
JavaScript
import { nextTestSetup } from 'e2e-utils'
|
|
|
|
describe('webpack-loader-resource-query', () => {
|
|
const { next, skipped } = nextTestSetup({
|
|
files: __dirname,
|
|
skipDeployment: true,
|
|
})
|
|
|
|
if (skipped) return
|
|
|
|
it('should pass query to loader', async () => {
|
|
await next.render$('/')
|
|
|
|
expect(next.cliOutput).toContain('resource query: ?test=hi')
|
|
})
|
|
|
|
it('should apply loader based on resourceQuery', async () => {
|
|
const $ = await next.render$('/')
|
|
const text = $('#reversed').text()
|
|
expect(text).toBe('dlroW olleH')
|
|
})
|
|
|
|
it('should apply loader based on resourceQuery regex', async () => {
|
|
const $ = await next.render$('/')
|
|
const text = $('#upper').text()
|
|
expect(text).toBe('HELLO WORLD')
|
|
})
|
|
})
|