@@ -25,12 +25,26 @@ const config: StorybookConfig = {
2525 viteFinal : async ( config ) => {
2626 const rootDir = fileURLToPath ( new URL ( "../../../" , import . meta. url ) )
2727 config . resolve = config . resolve || { }
28- config . resolve . alias = {
29- ...( config . resolve . alias || { } ) ,
30- "@" : rootDir ,
31- shared : path . resolve ( rootDir , "shared/src" ) ,
32- "@/shared" : path . resolve ( rootDir , "shared/src" ) ,
33- }
28+
29+ // Filter out any existing @ aliases and add our own at the beginning
30+ const existingAliases = Array . isArray ( config . resolve . alias )
31+ ? config . resolve . alias . filter (
32+ ( a ) =>
33+ ! (
34+ ( typeof a . find === "string" && a . find . startsWith ( "@" ) ) ||
35+ ( a . find instanceof RegExp && a . find . source . includes ( "@" ) )
36+ )
37+ )
38+ : Object . entries ( config . resolve . alias || { } )
39+ . filter ( ( [ find ] ) => ! find . startsWith ( "@" ) )
40+ . map ( ( [ find , replacement ] ) => ( { find, replacement } ) )
41+
42+ config . resolve . alias = [
43+ { find : / ^ @ \/ s h a r e d / , replacement : path . resolve ( rootDir , "shared/src" ) } ,
44+ { find : / ^ s h a r e d / , replacement : path . resolve ( rootDir , "shared/src" ) } ,
45+ { find : / ^ @ \/ / , replacement : `${ rootDir } /` } ,
46+ ...existingAliases ,
47+ ]
3448 return config
3549 } ,
3650}
0 commit comments