mirror of
https://github.com/nuxt/nuxt.git
synced 2024-11-25 15:15:19 +00:00
fix(nuxt): remove side-effect imports from page metadata (#6376)
This commit is contained in:
parent
07fa104b46
commit
60656dfa2c
@ -43,9 +43,18 @@ export const TransformMacroPlugin = createUnplugin((options: TransformMacroPlugi
|
||||
return result()
|
||||
}
|
||||
|
||||
const imports = findStaticImports(code)
|
||||
|
||||
// Purge all imports bringing side effects, such as CSS imports
|
||||
for (const entry of imports) {
|
||||
if (!entry.imports) {
|
||||
s.remove(entry.start, entry.end)
|
||||
}
|
||||
}
|
||||
|
||||
// [webpack] Re-export any imports from script blocks in the components
|
||||
// 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')
|
||||
const scriptImport = imports.find(i => parseQuery(i.specifier.replace('?macro=true', '')).type === 'script')
|
||||
if (scriptImport) {
|
||||
// https://github.com/vuejs/vue-loader/pull/1911
|
||||
// https://github.com/vitejs/vite/issues/8473
|
||||
|
@ -372,7 +372,7 @@ describe('dynamic paths', () => {
|
||||
|
||||
const html = await $fetch('/assets')
|
||||
const urls = Array.from(html.matchAll(/(href|src)="(.*?)"/g)).map(m => m[2])
|
||||
const cssURL = urls.find(u => /_nuxt\/entry.*\.css$/.test(u))
|
||||
const cssURL = urls.find(u => /_nuxt\/assets.*\.css$/.test(u))
|
||||
expect(cssURL).toBeDefined()
|
||||
const css = await $fetch(cssURL)
|
||||
const imageUrls = Array.from(css.matchAll(/url\(([^)]*)\)/g)).map(m => m[1].replace(/[-.][\w]{8}\./g, '.'))
|
||||
|
Loading…
Reference in New Issue
Block a user