@@ -12,6 +12,7 @@ import {
1212import { createRedirectsFromAstroRoutes } from '@astrojs/underscore-redirects' ;
1313import astroWhen from '@inox-tools/astro-when' ;
1414import { AstroError } from 'astro/errors' ;
15+ import { defaultServerConditions } from 'vite' ;
1516import { type GetPlatformProxyOptions , getPlatformProxy } from 'wrangler' ;
1617import {
1718 type CloudflareModulePluginExtra ,
@@ -213,12 +214,13 @@ export default function createIntegration(args?: Options): AstroIntegration {
213214 }
214215 }
215216
216- vite . resolve . conditions ||= [ ] ;
217- // We need those conditions, previous these conditions where applied at the esbuild step which we removed
218- // https://github.com/withastro/astro/pull/7092
219- vite . resolve . conditions . push ( 'workerd' , 'worker' ) ;
220-
217+ // Support `workerd` and `worker` conditions for the ssr environment
218+ // (previously supported in esbuild instead: https://github.com/withastro/astro/pull/7092)
221219 vite . ssr ||= { } ;
220+ vite . ssr . resolve ||= { } ;
221+ vite . ssr . resolve . conditions ||= [ ...defaultServerConditions ] ;
222+ vite . ssr . resolve . conditions . push ( 'workerd' , 'worker' ) ;
223+
222224 vite . ssr . target = 'webworker' ;
223225 vite . ssr . noExternal = true ;
224226
@@ -250,21 +252,6 @@ export default function createIntegration(args?: Options): AstroIntegration {
250252 ...vite . define ,
251253 } ;
252254 }
253- // we thought that vite config inside `if (target === 'server')` would not apply for client
254- // but it seems like the same `vite` reference is used for both
255- // so we need to reset the previous conflicting setting
256- // in the future we should look into a more robust solution
257- if ( target === 'client' ) {
258- vite . resolve ||= { } ;
259- vite . resolve . conditions ||= [ ] ;
260- vite . resolve . conditions = vite . resolve . conditions . filter (
261- ( c ) => c !== 'workerd' && c !== 'worker'
262- ) ;
263-
264- vite . build ||= { } ;
265- vite . build . rollupOptions ||= { } ;
266- vite . build . rollupOptions . output ||= { } ;
267- }
268255 } ,
269256 'astro:build:done' : async ( { pages, routes, dir, logger } ) => {
270257 await cloudflareModulePlugin . afterBuildCompleted ( _config ) ;
0 commit comments