@@ -14,7 +14,7 @@ module.exports = getPublicUrlOrPath;
14
14
/**
15
15
* Returns a URL or a path with slash at the end
16
16
* In production can be URL, abolute path, relative path
17
- * In development always will be an absolute path
17
+ * In development can be a relative or absolute path
18
18
* In development can use `path` module functions for operations
19
19
*
20
20
* @param {boolean } isEnvDevelopment
@@ -31,34 +31,31 @@ function getPublicUrlOrPath(isEnvDevelopment, homepage, envPublicUrl) {
31
31
? envPublicUrl
32
32
: envPublicUrl + '/' ;
33
33
34
+ // Some apps do not use client-side routing with pushState.
35
+ // For these, "$PUBLIC_URL" can be set to "." to enable relative asset paths.
36
+ if ( envPublicUrl . startsWith ( "." ) ) {
37
+ return envPublicUrl ;
38
+ }
39
+
34
40
// validate if `envPublicUrl` is a URL or path like
35
41
// `stubDomain` is ignored if `envPublicUrl` contains a domain
36
42
const validPublicUrl = new URL ( envPublicUrl , stubDomain ) ;
37
-
38
- return isEnvDevelopment
39
- ? envPublicUrl . startsWith ( '.' )
40
- ? '/'
41
- : validPublicUrl . pathname
42
- : // Some apps do not use client-side routing with pushState.
43
- // For these, "homepage" can be set to "." to enable relative asset paths.
44
- envPublicUrl ;
43
+ return isEnvDevelopment ? validPublicUrl . pathname : envPublicUrl ;
45
44
}
46
45
47
46
if ( homepage ) {
48
47
// strip last slash if exists
49
48
homepage = homepage . endsWith ( '/' ) ? homepage : homepage + '/' ;
50
49
50
+ // Some apps do not use client-side routing with pushState.
51
+ // For these, homepage can be set to "." to enable relative asset paths.
52
+ if ( homepage . startsWith ( "." ) ) {
53
+ return homepage ;
54
+ }
55
+
51
56
// validate if `homepage` is a URL or path like and use just pathname
52
57
const validHomepagePathname = new URL ( homepage , stubDomain ) . pathname ;
53
- return isEnvDevelopment
54
- ? homepage . startsWith ( '.' )
55
- ? '/'
56
- : validHomepagePathname
57
- : // Some apps do not use client-side routing with pushState.
58
- // For these, "homepage" can be set to "." to enable relative asset paths.
59
- homepage . startsWith ( '.' )
60
- ? homepage
61
- : validHomepagePathname ;
58
+ return isEnvDevelopment ? validHomepagePathname : homepage ;
62
59
}
63
60
64
61
return '/' ;
0 commit comments