-
-
Notifications
You must be signed in to change notification settings - Fork 116
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) { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. is name === 'client' a good way to check this? that would assume there can only be one client environment in an app. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. what if there was a tauri app and a web app at the same time, or two different clients? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Ah true, I think it should check the There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. is that a helper vite should expose? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I'm not sure if it's needed imo There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. well how are others going to use these exposed constants then? you'll always want the ones applicable to the environment you are in, no? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I'm not really sure what you mean. Do you have a pseudocode in mind for this? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. if vite-plugin-svelte needs to check There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I've already updated the code to use There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Looks like I need a combination of |
||
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.