@@ -4,7 +4,7 @@ import { readFileSync } from 'fs';
4
4
import { mergeAndConcat } from 'merge-anything' ;
5
5
import { createRequire } from 'module' ;
6
6
import solidRefresh from 'solid-refresh/babel' ;
7
- import { createFilter } from 'vite' ;
7
+ import { createFilter , version } from 'vite' ;
8
8
import type { Alias , AliasOptions , Plugin , FilterPattern } from 'vite' ;
9
9
import { crawlFrameworkPkgs } from 'vitefu' ;
10
10
@@ -14,6 +14,8 @@ const runtimePublicPath = '/@solid-refresh';
14
14
const runtimeFilePath = require . resolve ( 'solid-refresh/dist/solid-refresh.mjs' ) ;
15
15
const runtimeCode = readFileSync ( runtimeFilePath , 'utf-8' ) ;
16
16
17
+ const isVite6 = version . startsWith ( '6.' ) ;
18
+
17
19
/** Possible options for the extensions property */
18
20
export interface ExtensionOptions {
19
21
typescript ?: boolean ;
@@ -236,11 +238,13 @@ export default function solidPlugin(options: Partial<Options> = {}): Plugin {
236
238
*/
237
239
// esbuild: { include: /\.ts$/ },
238
240
resolve : {
239
- conditions : [
240
- 'solid' ,
241
- ...( replaceDev ? [ 'development' ] : [ ] ) ,
242
- ...( userConfig . mode === 'test' && ! options . ssr ? [ 'browser' ] : [ ] ) ,
243
- ] ,
241
+ conditions : isVite6
242
+ ? undefined
243
+ : [
244
+ 'solid' ,
245
+ ...( replaceDev ? [ 'development' ] : [ ] ) ,
246
+ ...( userConfig . mode === 'test' && ! options . ssr ? [ 'browser' ] : [ ] ) ,
247
+ ] ,
244
248
dedupe : nestedDeps ,
245
249
alias : [ { find : / ^ s o l i d - r e f r e s h $ / , replacement : runtimePublicPath } ] ,
246
250
} ,
@@ -253,6 +257,22 @@ export default function solidPlugin(options: Partial<Options> = {}): Plugin {
253
257
} ;
254
258
} ,
255
259
260
+ // @ts -ignore This hook only works in Vite 6
261
+ async configEnvironment ( name , config , opts ) {
262
+ config . resolve ??= { } ;
263
+ // Emulate Vite default fallback for `resolve.conditions` if not set
264
+ if ( config . resolve . conditions == null ) {
265
+ // @ts -ignore These exports only exist in Vite 6
266
+ const { defaultClientConditions, defaultServerConditions } = await import ( 'vite' ) ;
267
+ if ( config . consumer === 'client' || name === 'client' || opts . isSsrTargetWebworker ) {
268
+ config . resolve . conditions = [ ...defaultClientConditions ] ;
269
+ } else {
270
+ config . resolve . conditions = [ ...defaultServerConditions ] ;
271
+ }
272
+ }
273
+ config . resolve . conditions . push ( 'solid' ) ;
274
+ } ,
275
+
256
276
configResolved ( config ) {
257
277
needHmr = config . command === 'serve' && config . mode !== 'production' && options . hot !== false ;
258
278
} ,
0 commit comments