Skip to content

Handle query parameters in Vite #2629

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Aug 7, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 4 additions & 3 deletions packages/rollup/lib/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -32,8 +32,8 @@
* Callback called by Rollup and Vite to transform.
* @param {string} value
* File contents.
* @param {string} path
* File path.
* @param {string} id
* Module ID.
* @returns {Promise<SourceDescription | undefined>}
* Result.
*
Expand Down Expand Up @@ -80,14 +80,15 @@ export function rollup(options) {
...rest
})
},
async transform(value, path) {
async transform(value, id) {
if (!formatAwareProcessors) {
formatAwareProcessors = createFormatAwareProcessors({
SourceMapGenerator,
...rest
})
}

const [path] = id.split('?')
const file = new VFile({path, value})

if (
Expand Down
23 changes: 23 additions & 0 deletions packages/rollup/test/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -101,4 +101,27 @@ test('@mdx-js/rollup', async function (t) {
assert.doesNotMatch(code, /jsxs?\(/)
assert.match(code, /jsxDEV\(/)
})

await t.test('should handle query parameters in vite', async () => {
const result = /** @type {Array<RollupOutput>} */ (
await build({
build: {
lib: {
entry:
fileURLToPath(new URL('vite-entry.mdx', import.meta.url)) +
'?query=param',
name: 'query'
},
write: false
},
logLevel: 'silent',
plugins: [rollupMdx()]
})
)

const code = result[0].output[0].code

assert.match(code, /Hello Vite/)
assert.match(code, /jsxs?\(/)
})
})
Loading