-
-
Notifications
You must be signed in to change notification settings - Fork 120
feat!: vite 6 support #1020
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
feat!: vite 6 support #1020
Changes from 1 commit
d32301f
b39e222
dcec9af
e54a2a1
4fb1e5a
47bccb6
4f20ed2
04b1142
bd650b5
dbac1c3
e3a04c5
e1aa2a1
dd7a9cf
6d22716
5fbbe19
641301d
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -18,10 +18,6 @@ import { saveSvelteMetadata } from './utils/optimizer.js'; | |
import { VitePluginSvelteCache } from './utils/vite-plugin-svelte-cache.js'; | ||
import { loadRaw } from './utils/load-raw.js'; | ||
import * as svelteCompiler from 'svelte/compiler'; | ||
import { | ||
VITE_CLIENT_RESOLVE_CONDITIONS, | ||
VITE_SERVER_RESOLVE_CONDITIONS | ||
} from './utils/constants.js'; | ||
|
||
/** | ||
* @param {Partial<import('./public.d.ts').Options>} [inlineOptions] | ||
|
@@ -67,14 +63,31 @@ export function svelte(inlineOptions) { | |
log.debug('additional vite config', extraViteConfig, 'config'); | ||
return extraViteConfig; | ||
}, | ||
// @ts-ignore Allow exist in vite 6 | ||
configEnvironment(name, config) { | ||
|
||
// @ts-ignore This hook only works in Vite 6 | ||
async configEnvironment(name, config, opts) { | ||
config.resolve ??= {}; | ||
|
||
// Emulate Vite default fallback for `resolve.mainFields` if not set | ||
if (config.resolve.mainFields == null) { | ||
// These exports only exist in Vite 6 | ||
const { defaultClientMainFields, defaultServerMainFields } = await import('vite'); | ||
if (name === 'client' || opts.isSsrTargetWebworker) { | ||
config.resolve.mainFields = [...defaultClientMainFields]; | ||
} else { | ||
config.resolve.mainFields = [...defaultServerMainFields]; | ||
} | ||
} | ||
config.resolve.mainFields.unshift('svelte'); | ||
|
||
// Emulate Vite default fallback for `resolve.conditions` if not set | ||
if (config.resolve.conditions == null) { | ||
if (name === 'client') { | ||
config.resolve.conditions = [...VITE_CLIENT_RESOLVE_CONDITIONS]; | ||
// These exports only exist in Vite 6 | ||
const { defaultClientConditions, defaultServerConditions } = await import('vite'); | ||
if (name === 'client' || opts.isSsrTargetWebworker) { | ||
|
||
config.resolve.conditions = [...defaultClientConditions]; | ||
} else { | ||
config.resolve.conditions = [...VITE_SERVER_RESOLVE_CONDITIONS]; | ||
config.resolve.conditions = [...defaultServerConditions]; | ||
} | ||
} | ||
config.resolve.conditions.push('svelte'); | ||
|
Uh oh!
There was an error while loading. Please reload this page.