File tree Expand file tree Collapse file tree 3 files changed +19
-4
lines changed
packages/vite-plugin-svelte/src/utils Expand file tree Collapse file tree 3 files changed +19
-4
lines changed Original file line number Diff line number Diff line change 1+ ---
2+ ' @sveltejs/vite-plugin-svelte ' : patch
3+ ---
4+
5+ respect custom resolve.mainFields config when adding svelte
Original file line number Diff line number Diff line change 1- const VITE_RESOLVE_MAIN_FIELDS = [ 'module' , 'jsnext:main' , 'jsnext' ] ;
1+ export const VITE_RESOLVE_MAIN_FIELDS = [ 'module' , 'jsnext:main' , 'jsnext' ] ;
22
3- export const SVELTE_RESOLVE_MAIN_FIELDS = [ 'svelte' , ... VITE_RESOLVE_MAIN_FIELDS ] ;
3+ export const SVELTE_RESOLVE_MAIN_FIELDS = [ 'svelte' ] ;
44
55export const SVELTE_IMPORTS = [
66 'svelte/animate' ,
Original file line number Diff line number Diff line change 66 SVELTE_EXPORT_CONDITIONS ,
77 SVELTE_HMR_IMPORTS ,
88 SVELTE_IMPORTS ,
9- SVELTE_RESOLVE_MAIN_FIELDS
9+ SVELTE_RESOLVE_MAIN_FIELDS ,
10+ VITE_RESOLVE_MAIN_FIELDS
1011} from './constants' ;
1112// eslint-disable-next-line node/no-missing-import
1213import type { CompileOptions , Warning } from 'svelte/types/compiler/interfaces' ;
@@ -324,9 +325,18 @@ export async function buildExtraViteConfig(
324325 options : PreResolvedOptions ,
325326 config : UserConfig
326327) : Promise < Partial < UserConfig > > {
328+ // make sure we only readd vite default mainFields when no other plugin has changed the config already
329+ // see https://github.com/sveltejs/vite-plugin-svelte/issues/581
330+ if ( ! config . resolve ) {
331+ config . resolve = { } ;
332+ }
333+ config . resolve . mainFields = [
334+ ...SVELTE_RESOLVE_MAIN_FIELDS ,
335+ ...( config . resolve . mainFields ?? VITE_RESOLVE_MAIN_FIELDS )
336+ ] ;
337+
327338 const extraViteConfig : Partial < UserConfig > = {
328339 resolve : {
329- mainFields : [ ...SVELTE_RESOLVE_MAIN_FIELDS ] ,
330340 dedupe : [ ...SVELTE_IMPORTS , ...SVELTE_HMR_IMPORTS ] ,
331341 conditions : [ ...SVELTE_EXPORT_CONDITIONS ]
332342 }
You can’t perform that action at this time.
0 commit comments