diff --git a/.changeset/chilled-tigers-flash.md b/.changeset/chilled-tigers-flash.md new file mode 100644 index 000000000..b568a5b1b --- /dev/null +++ b/.changeset/chilled-tigers-flash.md @@ -0,0 +1,5 @@ +--- +'@sveltejs/vite-plugin-svelte': patch +--- + +Skip Vite resolve workaround on Vite 4.1+ or Svelte 4+ diff --git a/packages/vite-plugin-svelte/src/index.ts b/packages/vite-plugin-svelte/src/index.ts index 3b0e374e2..30f984fa3 100644 --- a/packages/vite-plugin-svelte/src/index.ts +++ b/packages/vite-plugin-svelte/src/index.ts @@ -1,5 +1,13 @@ import fs from 'fs'; -import { HmrContext, ModuleNode, Plugin, ResolvedConfig, UserConfig } from 'vite'; +import { VERSION as svelteVersion } from 'svelte/compiler'; +import { + HmrContext, + ModuleNode, + Plugin, + ResolvedConfig, + UserConfig, + version as viteVersion +} from 'vite'; // eslint-disable-next-line node/no-missing-import import { isDepExcluded } from 'vitefu'; import { handleHotUpdate } from './handle-hot-update'; @@ -35,6 +43,9 @@ interface PluginAPI { // TODO expose compile cache here so other utility plugins can use it } +const isVite4_0 = viteVersion.startsWith('4.0'); +const isSvelte3 = svelteVersion.startsWith('3'); + export function svelte(inlineOptions?: Partial): Plugin[] { if (process.env.DEBUG != null) { log.setLevel('debug'); @@ -135,7 +146,8 @@ export function svelte(inlineOptions?: Partial): Plugin[] { } } - if (ssr && importee === 'svelte') { + // TODO: remove this after bumping peerDep on Vite to 4.1+ or Svelte to 4.0+ + if (isVite4_0 && isSvelte3 && ssr && importee === 'svelte') { if (!resolvedSvelteSSR) { resolvedSvelteSSR = this.resolve('svelte/ssr', undefined, { skipSelf: true }).then( (svelteSSR) => {