fix(nuxt): handle vite preload-helper id with extension (#23230)

This commit is contained in:
翠 / green 2023-09-15 21:16:09 +09:00 committed by GitHub
parent bdbb87ac0b
commit 3334ca26c6
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 5 additions and 1 deletions

View File

@ -1,11 +1,15 @@
import MagicString from 'magic-string' import MagicString from 'magic-string'
import type { Plugin } from 'vite' import type { Plugin } from 'vite'
const vitePreloadHelperId = '\0vite/preload-helper'
// TODO: remove this function when we upgrade to vite 5
export function chunkErrorPlugin (options: { sourcemap?: boolean }): Plugin { export function chunkErrorPlugin (options: { sourcemap?: boolean }): Plugin {
return { return {
name: 'nuxt:chunk-error', name: 'nuxt:chunk-error',
transform (code, id) { transform (code, id) {
if (id !== '\0vite/preload-helper' || code.includes('nuxt.preloadError')) { return } // Vite 5 has an id with extension
if (!(id === vitePreloadHelperId || id === `${vitePreloadHelperId}.js`) || code.includes('nuxt.preloadError')) { return }
const s = new MagicString(code) const s = new MagicString(code)
s.replace(/__vitePreload/g, '___vitePreload') s.replace(/__vitePreload/g, '___vitePreload')