File tree 3 files changed +19
-4
lines changed
packages/vite-plugin-svelte/src/utils 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' ] ;
2
2
3
- export const SVELTE_RESOLVE_MAIN_FIELDS = [ 'svelte' , ... VITE_RESOLVE_MAIN_FIELDS ] ;
3
+ export const SVELTE_RESOLVE_MAIN_FIELDS = [ 'svelte' ] ;
4
4
5
5
export const SVELTE_IMPORTS = [
6
6
'svelte/animate' ,
Original file line number Diff line number Diff line change 6
6
SVELTE_EXPORT_CONDITIONS ,
7
7
SVELTE_HMR_IMPORTS ,
8
8
SVELTE_IMPORTS ,
9
- SVELTE_RESOLVE_MAIN_FIELDS
9
+ SVELTE_RESOLVE_MAIN_FIELDS ,
10
+ VITE_RESOLVE_MAIN_FIELDS
10
11
} from './constants' ;
11
12
// eslint-disable-next-line node/no-missing-import
12
13
import type { CompileOptions , Warning } from 'svelte/types/compiler/interfaces' ;
@@ -324,9 +325,18 @@ export async function buildExtraViteConfig(
324
325
options : PreResolvedOptions ,
325
326
config : UserConfig
326
327
) : 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
+
327
338
const extraViteConfig : Partial < UserConfig > = {
328
339
resolve : {
329
- mainFields : [ ...SVELTE_RESOLVE_MAIN_FIELDS ] ,
330
340
dedupe : [ ...SVELTE_IMPORTS , ...SVELTE_HMR_IMPORTS ] ,
331
341
conditions : [ ...SVELTE_EXPORT_CONDITIONS ]
332
342
}
You can’t perform that action at this time.
0 commit comments