Skip to content

Commit e1aa2a1

Browse files
committed
chore: fix logic
1 parent e3a04c5 commit e1aa2a1

File tree

2 files changed

+9
-7
lines changed

2 files changed

+9
-7
lines changed

packages/vite-plugin-svelte/src/index.js

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -66,12 +66,12 @@ export function svelte(inlineOptions) {
6666
return extraViteConfig;
6767
},
6868

69-
configEnvironment(_, config, opts) {
70-
ensureConfigEnvironmentMainFields(config, opts);
69+
configEnvironment(name, config, opts) {
70+
ensureConfigEnvironmentMainFields(name, config, opts);
7171
// @ts-expect-error the function above should make `resolve.mainFields` non-nullable
7272
config.resolve.mainFields.unshift('svelte');
7373

74-
ensureConfigEnvironmentConditions(config, opts);
74+
ensureConfigEnvironmentConditions(name, config, opts);
7575
// @ts-expect-error the function above should make `resolve.conditions` non-nullable
7676
config.resolve.conditions.push('svelte');
7777
},

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

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -605,13 +605,14 @@ export function patchResolvedViteConfig(viteConfig, options) {
605605

606606
/**
607607
* Mutates `config` to ensure `resolve.mainFields` is set. If unset, it emulates Vite's default fallback.
608+
* @param {string} name
608609
* @param {import('vite').EnvironmentOptions} config
609610
* @param {{ isSsrTargetWebworker?: boolean }} opts
610611
*/
611-
export function ensureConfigEnvironmentMainFields(config, opts) {
612+
export function ensureConfigEnvironmentMainFields(name, config, opts) {
612613
config.resolve ??= {};
613614
if (config.resolve.mainFields == null) {
614-
if (config.consumer === 'client' || opts.isSsrTargetWebworker) {
615+
if (config.consumer === 'client' || name === 'client' || opts.isSsrTargetWebworker) {
615616
config.resolve.mainFields = [...defaultClientMainFields];
616617
} else {
617618
config.resolve.mainFields = [...defaultServerMainFields];
@@ -622,13 +623,14 @@ export function ensureConfigEnvironmentMainFields(config, opts) {
622623

623624
/**
624625
* Mutates `config` to ensure `resolve.conditions` is set. If unset, it emulates Vite's default fallback.
626+
* @param {string} name
625627
* @param {import('vite').EnvironmentOptions} config
626628
* @param {{ isSsrTargetWebworker?: boolean }} opts
627629
*/
628-
export function ensureConfigEnvironmentConditions(config, opts) {
630+
export function ensureConfigEnvironmentConditions(name, config, opts) {
629631
config.resolve ??= {};
630632
if (config.resolve.conditions == null) {
631-
if (config.consumer === 'client' || opts.isSsrTargetWebworker) {
633+
if (config.consumer === 'client' || name === 'client' || opts.isSsrTargetWebworker) {
632634
config.resolve.conditions = [...defaultClientConditions];
633635
} else {
634636
config.resolve.conditions = [...defaultServerConditions];

0 commit comments

Comments
 (0)