File tree Expand file tree Collapse file tree 3 files changed +46
-9
lines changed
packages/vite-plugin-svelte/src/utils Expand file tree Collapse file tree 3 files changed +46
-9
lines changed Original file line number Diff line number Diff line change 1+ ---
2+ ' @sveltejs/vite-plugin-svelte ' : major
3+ ---
4+
5+ automatically include svelte in vite config optimizeDeps.include
6+
7+ Previously, svelte was automatically excluded. We include it now by default to improve deduplication.
8+
9+ As a result, svelte is pre-bundled by vite during dev, which it logs when starting the devserver
10+
11+ ``` shell
12+ Pre-bundling dependencies:
13+ svelte/animate
14+ svelte/easing
15+ svelte/internal
16+ svelte/motion
17+ svelte/store
18+ (...and 2 more)
19+ (this will be run only when your dependencies or config have changed)
20+ ```
21+
22+ And it's also visible in the browsers network tab, where requests for svelte imports now start with ` node_modules/.vite/ ` during dev.
23+
24+ Check out the [ vite pre-bundling documentation] ( https://vitejs.dev/guide/dep-pre-bundling.html ) for more information.
25+
26+ To get the old behavior back, add the following to your vite config
27+
28+ ``` js
29+ optimizeDeps: {
30+ exclude: [' svelte' ];
31+ }
32+ ```
Original file line number Diff line number Diff line change @@ -7,6 +7,7 @@ export const SVELTE_IMPORTS = [
77 'svelte/easing' ,
88 'svelte/internal' ,
99 'svelte/motion' ,
10+ 'svelte/ssr' ,
1011 'svelte/store' ,
1112 'svelte/transition' ,
1213 'svelte'
Original file line number Diff line number Diff line change @@ -179,20 +179,24 @@ export function buildExtraViteConfig(
179179 options : ResolvedOptions ,
180180 config : UserConfig
181181) : Partial < UserConfig > {
182- const allSvelteImports = [ ...SVELTE_IMPORTS , ...SVELTE_HMR_IMPORTS ] ;
183-
184- // exclude svelte imports from optimization unless explicitly included
185- const excludeFromOptimize = allSvelteImports . filter (
186- ( x ) => ! config . optimizeDeps ?. include ?. includes ( x )
187- ) ;
188-
182+ // include svelte imports for optimization unless explicitly excluded
183+ const include : string [ ] = [ ] ;
184+ const exclude : string [ ] = [ 'svelte-hmr' ] ;
185+ const isSvelteExcluded = config . optimizeDeps ?. exclude ?. includes ( 'svelte' ) ;
186+ if ( ! isSvelteExcluded ) {
187+ log . debug ( `adding bare svelte packages to optimizeDeps.include: ${ SVELTE_IMPORTS . join ( ', ' ) } ` ) ;
188+ include . push ( ...SVELTE_IMPORTS ) ;
189+ } else {
190+ log . debug ( '"svelte" is excluded in optimizeDeps.exclude, skipped adding it to include.' ) ;
191+ }
189192 const extraViteConfig : Partial < UserConfig > = {
190193 optimizeDeps : {
191- exclude : excludeFromOptimize
194+ include,
195+ exclude
192196 } ,
193197 resolve : {
194198 mainFields : [ ...SVELTE_RESOLVE_MAIN_FIELDS ] ,
195- dedupe : allSvelteImports
199+ dedupe : [ ... SVELTE_IMPORTS , ... SVELTE_HMR_IMPORTS ]
196200 }
197201 // this option is still awaiting a PR in vite to be supported
198202 // see https://github.com/sveltejs/vite-plugin-svelte/issues/60
You can’t perform that action at this time.
0 commit comments