11import path from "node:path" ;
2- import { join , resolve } from "pathe" ;
2+ import { resolve } from "pathe" ;
33import type { DevEnvironment , EnvironmentModuleNode } from "vite" ;
44
55const prepareTransformResult = async ( vite : DevEnvironment , module : EnvironmentModuleNode ) => {
@@ -62,27 +62,10 @@ async function findModuleDependencies(
6262
6363 if ( module . url . endsWith ( ".css" ) || module . url . includes ( "node_modules" ) ) return ;
6464
65- if ( ssr ) {
66- await prepareTransformResult ( vite , module ) ;
67- if ( module . transformResult ?. deps ) {
68- for ( const url of module . transformResult . deps ) {
69- await addByUrl ( url , ssr ) ;
70- }
71-
72- // Parallel version with incorrect style order
73- /* node.ssrTransformResult.deps.forEach((url) =>
74- branches.push(add_by_url(url, ssr)),
75- ); */
76- }
77- } else {
78- for ( const { url } of module . importedModules ) {
79- const node = await getViteModuleNode ( vite , url , ssr ) ;
80-
81- if ( node && ! deps . has ( node ) ) {
82- deps . add ( node ) ;
83- await findModuleDependencies ( vite , node , ssr , deps ) ;
84- }
85- }
65+ if ( ssr ) await prepareTransformResult ( vite , module ) ;
66+
67+ for ( const mod of module . importedModules ) {
68+ await addByUrl ( mod . url , ssr ) ;
8669 }
8770}
8871
@@ -138,9 +121,6 @@ async function findFilesDepedencies(
138121 return deps ;
139122}
140123
141- const injectQuery = ( url : string , query : string ) =>
142- url . includes ( "?" ) ? url . replace ( "?" , `?${ query } &` ) : `${ url } ?${ query } ` ;
143-
144124export async function findStylesInModuleGraph (
145125 vite : DevEnvironment ,
146126 id : string ,
@@ -153,13 +133,8 @@ export async function findStylesInModuleGraph(
153133 const styles : Record < string , any > = { } ;
154134
155135 for ( const dep of dependencies ) {
156- if ( isCssFile ( dep . url ) ) {
157- let depURL = dep . url ;
158- if ( ! isCssUrlWithoutSideEffects ( depURL ) ) {
159- depURL = injectQuery ( dep . url , "inline" ) ;
160- }
161-
162- styles [ join ( vite . config . root , dep . url ) ] = dep . url ;
136+ if ( isCssFile ( dep . url ) && dep . id ) {
137+ styles [ dep . id ] = dep . url ;
163138 }
164139 }
165140
0 commit comments