async function buildExtraViteConfig(options, config) {
	/** @type {Partial<import('vite').UserConfig>} */
	const extraViteConfig = {
		resolve: {
			dedupe: [...SVELTE_IMPORTS]
		}
		// this option is still awaiting a PR in vite to be supported
		// see https://github.com/sveltejs/vite-plugin-svelte/issues/60
		// knownJsSrcExtensions: options.extensions
	};

	const extraSvelteConfig = buildExtraConfigForSvelte(config);
	const extraDepsConfig = await buildExtraConfigForDependencies(options, config);
	// merge extra svelte and deps config, but make sure dep values are not contradicting svelte
	extraViteConfig.optimizeDeps = {
		include: [
			...extraSvelteConfig.optimizeDeps.include,
			...extraDepsConfig.optimizeDeps.include.filter(
				(dep) => !isDepExcluded(dep, extraSvelteConfig.optimizeDeps.exclude)
			)
		],
		exclude: [
			...extraSvelteConfig.optimizeDeps.exclude,
			...extraDepsConfig.optimizeDeps.exclude.filter(
				(dep) => !isDepIncluded(dep, extraSvelteConfig.optimizeDeps.include)
			)
		]
	};

	extraViteConfig.ssr = {
		external: [
			...extraSvelteConfig.ssr.external,
			...extraDepsConfig.ssr.external.filter(
				(dep) => !isDepNoExternaled(dep, extraSvelteConfig.ssr.noExternal)
			)
		],
		noExternal: [
			...extraSvelteConfig.ssr.noExternal,
			...extraDepsConfig.ssr.noExternal.filter(
				(dep) => !isDepExternaled(dep, extraSvelteConfig.ssr.external)
			)
		]
	};

	// handle prebundling for svelte files
	if (options.prebundleSvelteLibraries) {
		extraViteConfig.optimizeDeps = {
			...extraViteConfig.optimizeDeps,
			// Experimental Vite API to allow these extensions to be scanned and prebundled
			extensions: options.extensions ?? ['.svelte']
		};
		// Add optimizer plugins to prebundle Svelte files.
		// Currently a placeholder as more information is needed after Vite config is resolved,
		// the added plugins are patched in `patchResolvedViteConfig()`
		if (rolldownVersion) {
			/**
			 *
			 * @param {string} name
			 * @returns {import('vite').Rollup.Plugin}
			 */
			const placeholderRolldownOptimizerPlugin = (name) => ({
				name,
				options() {},
				buildStart() {},
				buildEnd() {},
				transform: { filter: { id: /^$/ }, handler() {} }
			});
			//@ts-expect-error rolldown types not finished
			extraViteConfig.optimizeDeps.rollupOptions = {
				plugins: [
					placeholderRolldownOptimizerPlugin(optimizeSveltePluginName),
					placeholderRolldownOptimizerPlugin(optimizeSvelteModulePluginName)
				]
			};
		} else {
			extraViteConfig.optimizeDeps.esbuildOptions = {
				plugins: [
					{ name: optimizeSveltePluginName, setup: () => {} },
					{ name: optimizeSvelteModulePluginName, setup: () => {} }
				]
			};
		}
	}

	// enable hmrPartialAccept if not explicitly disabled
	if (config.experimental?.hmrPartialAccept !== false) {
		log.debug('enabling "experimental.hmrPartialAccept" in vite config', undefined, 'config');
		extraViteConfig.experimental = { hmrPartialAccept: true };
	}
	validateViteConfig(extraViteConfig, config, options);
	return extraViteConfig;
}
@param {import('../types/options.d.ts').PreResolvedOptions} options
@param {import('vite').UserConfig} config
@returns {Promise<Partial<import('vite').UserConfig>>}