Skip to content

Commit 7150c4c

Browse files
committed
fixes for rolldown: remove duplicate optimizer setup and use svelte5 syntax to mount test app
1 parent 04531a9 commit 7150c4c

File tree

2 files changed

+3
-87
lines changed
  • packages

2 files changed

+3
-87
lines changed
Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,3 @@
11
import App from './App.svelte';
2-
3-
if (App.toString().startsWith('class ')) {
4-
new App({ target: document.body });
5-
} else {
6-
import('svelte').then(({ mount }) => mount(App, { target: document.body }));
7-
}
2+
import { mount } from 'svelte';
3+
mount(App, { target: document.body });

packages/vite-plugin-svelte/src/utils/options.js

Lines changed: 1 addition & 81 deletions
Original file line numberDiff line numberDiff line change
@@ -5,9 +5,7 @@ const {
55
defaultServerMainFields,
66
defaultClientConditions,
77
defaultServerConditions,
8-
normalizePath,
9-
//@ts-expect-error rolldownVersion not in type
10-
rolldownVersion
8+
normalizePath
119
} = vite;
1210
import { log } from './log.js';
1311
import { loadSvelteConfig } from './load-svelte-config.js';
@@ -20,12 +18,6 @@ import {
2018
} from './constants.js';
2119

2220
import path from 'node:path';
23-
import {
24-
optimizeSvelteModulePluginName,
25-
optimizeSveltePluginName,
26-
patchESBuildOptimizerPlugin,
27-
patchRolldownOptimizerPlugin
28-
} from './optimizer-plugins.js';
2921
import { addExtraPreprocessors } from './preprocess.js';
3022
import deepmerge from 'deepmerge';
3123
import {
@@ -379,46 +371,6 @@ export async function buildExtraViteConfig(options, config) {
379371
]
380372
};
381373

382-
// handle prebundling for svelte files
383-
if (options.prebundleSvelteLibraries) {
384-
extraViteConfig.optimizeDeps = {
385-
...extraViteConfig.optimizeDeps,
386-
// Experimental Vite API to allow these extensions to be scanned and prebundled
387-
extensions: options.extensions ?? ['.svelte']
388-
};
389-
// Add optimizer plugins to prebundle Svelte files.
390-
// Currently a placeholder as more information is needed after Vite config is resolved,
391-
// the added plugins are patched in `patchResolvedViteConfig()`
392-
if (rolldownVersion) {
393-
/**
394-
*
395-
* @param {string} name
396-
* @returns {import('vite').Rollup.Plugin}
397-
*/
398-
const placeholderRolldownOptimizerPlugin = (name) => ({
399-
name,
400-
options() {},
401-
buildStart() {},
402-
buildEnd() {},
403-
transform: { filter: { id: /^$/ }, handler() {} }
404-
});
405-
//@ts-expect-error rolldown types not finished
406-
extraViteConfig.optimizeDeps.rollupOptions = {
407-
plugins: [
408-
placeholderRolldownOptimizerPlugin(optimizeSveltePluginName),
409-
placeholderRolldownOptimizerPlugin(optimizeSvelteModulePluginName)
410-
]
411-
};
412-
} else {
413-
extraViteConfig.optimizeDeps.esbuildOptions = {
414-
plugins: [
415-
{ name: optimizeSveltePluginName, setup: () => {} },
416-
{ name: optimizeSvelteModulePluginName, setup: () => {} }
417-
]
418-
};
419-
}
420-
}
421-
422374
// enable hmrPartialAccept if not explicitly disabled
423375
if (config.experimental?.hmrPartialAccept !== false) {
424376
log.debug('enabling "experimental.hmrPartialAccept" in vite config', undefined, 'config');
@@ -602,38 +554,6 @@ function buildExtraConfigForSvelte(config) {
602554
return { optimizeDeps: { include, exclude }, ssr: { noExternal, external } };
603555
}
604556

605-
/**
606-
* @param {import('vite').ResolvedConfig} viteConfig
607-
* @param {import('../types/options.d.ts').ResolvedOptions} options
608-
*/
609-
export function patchResolvedViteConfig(viteConfig, options) {
610-
if (options.preprocess) {
611-
for (const preprocessor of arraify(options.preprocess)) {
612-
if (preprocessor.style && '__resolvedConfig' in preprocessor.style) {
613-
preprocessor.style.__resolvedConfig = viteConfig;
614-
}
615-
}
616-
}
617-
if (rolldownVersion) {
618-
const plugins =
619-
// @ts-expect-error not typed
620-
viteConfig.optimizeDeps.rollupOptions?.plugins?.filter((p) =>
621-
[optimizeSveltePluginName, optimizeSvelteModulePluginName].includes(p.name)
622-
) ?? [];
623-
for (const plugin of plugins) {
624-
patchRolldownOptimizerPlugin(plugin, options);
625-
}
626-
} else {
627-
const plugins =
628-
viteConfig.optimizeDeps.esbuildOptions?.plugins?.filter((p) =>
629-
[optimizeSveltePluginName, optimizeSvelteModulePluginName].includes(p.name)
630-
) ?? [];
631-
for (const plugin of plugins) {
632-
patchESBuildOptimizerPlugin(plugin, options);
633-
}
634-
}
635-
}
636-
637557
/**
638558
* Mutates `config` to ensure `resolve.mainFields` is set. If unset, it emulates Vite's default fallback.
639559
* @param {string} name

0 commit comments

Comments
 (0)