Skip to content

Commit 3185a36

Browse files
benmccanndominikg
andauthored
Skip Vite resolve workaround on Vite 4.1+ or Svelte 4+ (#622)
* Skip Vite resolve workaround on Vite 4.1+ * Update packages/vite-plugin-svelte/src/index.ts Co-authored-by: Dominik G. <[email protected]> * Update packages/vite-plugin-svelte/src/index.ts Co-authored-by: Dominik G. <[email protected]> * Update packages/vite-plugin-svelte/src/index.ts Co-authored-by: Dominik G. <[email protected]> * Check Svelte version as well * move startsWith to constants --------- Co-authored-by: Dominik G. <[email protected]>
1 parent cf4f07a commit 3185a36

File tree

2 files changed

+19
-2
lines changed

2 files changed

+19
-2
lines changed

.changeset/chilled-tigers-flash.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
'@sveltejs/vite-plugin-svelte': patch
3+
---
4+
5+
Skip Vite resolve workaround on Vite 4.1+ or Svelte 4+

packages/vite-plugin-svelte/src/index.ts

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,13 @@
11
import fs from 'fs';
2-
import { HmrContext, ModuleNode, Plugin, ResolvedConfig, UserConfig } from 'vite';
2+
import { VERSION as svelteVersion } from 'svelte/compiler';
3+
import {
4+
HmrContext,
5+
ModuleNode,
6+
Plugin,
7+
ResolvedConfig,
8+
UserConfig,
9+
version as viteVersion
10+
} from 'vite';
311
// eslint-disable-next-line node/no-missing-import
412
import { isDepExcluded } from 'vitefu';
513
import { handleHotUpdate } from './handle-hot-update';
@@ -35,6 +43,9 @@ interface PluginAPI {
3543
// TODO expose compile cache here so other utility plugins can use it
3644
}
3745

46+
const isVite4_0 = viteVersion.startsWith('4.0');
47+
const isSvelte3 = svelteVersion.startsWith('3');
48+
3849
export function svelte(inlineOptions?: Partial<Options>): Plugin[] {
3950
if (process.env.DEBUG != null) {
4051
log.setLevel('debug');
@@ -135,7 +146,8 @@ export function svelte(inlineOptions?: Partial<Options>): Plugin[] {
135146
}
136147
}
137148

138-
if (ssr && importee === 'svelte') {
149+
// TODO: remove this after bumping peerDep on Vite to 4.1+ or Svelte to 4.0+
150+
if (isVite4_0 && isSvelte3 && ssr && importee === 'svelte') {
139151
if (!resolvedSvelteSSR) {
140152
resolvedSvelteSSR = this.resolve('svelte/ssr', undefined, { skipSelf: true }).then(
141153
(svelteSSR) => {

0 commit comments

Comments
 (0)