@@ -13,17 +13,13 @@ export const MIDDLEWARE_MODULE_ID = '\0astro-internal:middleware';
1313const NOOP_MIDDLEWARE = '\0noop-middleware' ;
1414
1515export function vitePluginMiddleware ( { settings } : { settings : AstroSettings } ) : VitePlugin {
16- let isCommandBuild = false ;
1716 let resolvedMiddlewareId : string | undefined = undefined ;
1817 const hasIntegrationMiddleware =
1918 settings . middlewares . pre . length > 0 || settings . middlewares . post . length > 0 ;
2019 let userMiddlewareIsPresent = false ;
2120
2221 return {
2322 name : '@astro/plugin-middleware' ,
24- config ( _ , { command } ) {
25- isCommandBuild = command === 'build' ;
26- } ,
2723 async resolveId ( id ) {
2824 if ( id === MIDDLEWARE_MODULE_ID ) {
2925 const middlewareId = await this . resolve (
@@ -53,15 +49,6 @@ export function vitePluginMiddleware({ settings }: { settings: AstroSettings }):
5349 if ( ! userMiddlewareIsPresent && settings . config . i18n ?. routing === 'manual' ) {
5450 throw new AstroError ( MissingMiddlewareForInternationalization ) ;
5551 }
56- // In the build, tell Vite to emit this file
57- if ( isCommandBuild ) {
58- this . emitFile ( {
59- type : 'chunk' ,
60- preserveSignature : 'strict' ,
61- fileName : 'middleware.mjs' ,
62- id,
63- } ) ;
64- }
6552
6653 const preMiddleware = createMiddlewareImports ( settings . middlewares . pre , 'pre' ) ;
6754 const postMiddleware = createMiddlewareImports ( settings . middlewares . post , 'post' ) ;
@@ -124,7 +111,7 @@ export function vitePluginMiddlewareBuild(
124111
125112 writeBundle ( _ , bundle ) {
126113 for ( const [ chunkName , chunk ] of Object . entries ( bundle ) ) {
127- if ( chunk . type !== 'asset' && chunk . fileName === 'middleware.mjs' ) {
114+ if ( chunk . type !== 'asset' && chunk . facadeModuleId === MIDDLEWARE_MODULE_ID ) {
128115 const outputDirectory = getOutputDirectory ( opts . settings . config ) ;
129116 internals . middlewareEntryPoint = new URL ( chunkName , outputDirectory ) ;
130117 }
0 commit comments