File tree 4 files changed +13
-5
lines changed
4 files changed +13
-5
lines changed Original file line number Diff line number Diff line change @@ -483,7 +483,15 @@ export async function resolveConfig(
483
483
// resolve public base url
484
484
const isBuild = command === 'build'
485
485
const relativeBaseShortcut = config . base === '' || config . base === './'
486
- const base = relativeBaseShortcut && ! isBuild ? '/' : config . base ?? '/'
486
+
487
+ // During dev, we ignore relative base and fallback to '/'
488
+ // For the SSR build, relative base isn't possible by means
489
+ // of import.meta.url. The user will be able to work out a setup
490
+ // using experimental.buildAdvancedBaseOptions
491
+ const base =
492
+ relativeBaseShortcut && ( ! isBuild || config . build ?. ssr )
493
+ ? '/'
494
+ : config . base ?? '/'
487
495
let resolvedBase = relativeBaseShortcut
488
496
? base
489
497
: resolveBaseUrl ( base , isBuild , logger , 'base' )
Original file line number Diff line number Diff line change @@ -105,7 +105,7 @@ export function assetPlugin(config: ResolvedConfig): Plugin {
105
105
) => {
106
106
return base . runtime
107
107
? `"+${ base . runtime ( JSON . stringify ( filename ) ) } +"`
108
- : base . relative
108
+ : base . relative && ! config . build . ssr
109
109
? absoluteUrlPathInterpolation ( filename )
110
110
: JSON . stringify ( ( base . url ?? config . base ) + filename ) . slice ( 1 , - 1 )
111
111
}
Original file line number Diff line number Diff line change @@ -469,7 +469,7 @@ export function cssPostPlugin(config: ResolvedConfig): Plugin {
469
469
chunkCSS = chunkCSS . replace ( assetUrlRE , ( _ , fileHash , postfix = '' ) => {
470
470
const filename = getAssetFilename ( fileHash , config ) + postfix
471
471
chunk . viteMetadata . importedAssets . add ( cleanUrl ( filename ) )
472
- if ( assetsBase . relative ) {
472
+ if ( assetsBase . relative && ! config . build . ssr ) {
473
473
// relative base + extracted CSS
474
474
const relativePath = path . posix . relative ( cssAssetDirname ! , filename )
475
475
return relativePath . startsWith ( '.' )
@@ -488,7 +488,7 @@ export function cssPostPlugin(config: ResolvedConfig): Plugin {
488
488
)
489
489
chunkCSS = chunkCSS . replace ( publicAssetUrlRE , ( _ , hash ) => {
490
490
const publicUrl = publicAssetUrlMap . get ( hash ) !
491
- if ( publicBase . relative ) {
491
+ if ( publicBase . relative && ! config . build . ssr ) {
492
492
return relativePathToPublicFromCSS + publicUrl
493
493
} else {
494
494
// publicBase.runtime has no effect for assets in CSS
Original file line number Diff line number Diff line change @@ -338,7 +338,7 @@ export function webWorkerPlugin(config: ResolvedConfig): Plugin {
338
338
} else {
339
339
// Relative base
340
340
let outputFilepath : string
341
- if ( assetsBase . relative ) {
341
+ if ( assetsBase . relative && ! config . build . ssr ) {
342
342
outputFilepath = path . posix . relative (
343
343
path . dirname ( chunk . fileName ) ,
344
344
filename
You can’t perform that action at this time.
0 commit comments