Skip to content
This repository has been archived by the owner on Apr 6, 2023. It is now read-only.

fix(nuxt): don't add macro query to the end of id #5413

Merged
merged 2 commits into from Jun 12, 2022
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
5 changes: 4 additions & 1 deletion packages/nuxt/src/pages/macros.ts
Expand Up @@ -46,7 +46,10 @@ export const TransformMacroPlugin = createUnplugin((options: TransformMacroPlugi
// with workaround for vue-loader bug: https://github.com/vuejs/vue-loader/pull/1911
const scriptImport = findStaticImports(code).find(i => parseQuery(i.specifier.replace('?macro=true', '')).type === 'script')
if (scriptImport) {
const specifier = withQuery(scriptImport.specifier.replace('?macro=true', ''), { macro: 'true' })
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

withQuery doesn't changes the order by default if we didn't first remove ?macro=true. /cc @danielroe Was there any reason you used replaced initially?

image

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ah, very good point. It was to work around another vite issue, where any existing query was not respected. (So id that vite produced was something like ?macro=true?lang=test.jsx.)

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for explaining. Does the issue exists anymore?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ah, I see I was wrong - it was a vue-loader bug: vuejs/vue-loader#1911 which still exists with an open PR to fix it. I'll need to check that this PR doesn't introduce a regression with webpack.

// https://github.com/vuejs/vue-loader/pull/1911
// https://github.com/vitejs/vite/issues/8473
const parsed = parseURL(scriptImport.specifier.replace('?macro=true', ''))
pi0 marked this conversation as resolved.
Show resolved Hide resolved
const specifier = withQuery(parsed.pathname, { macro: 'true', ...parseQuery(parsed.search) })
s.overwrite(0, code.length, `export { meta } from "${specifier}"`)
return result()
}
Expand Down