@@ -91,12 +91,26 @@ export function prodExposePlugin(
91
91
const assetsDir = __VITE_ASSETS_DIR_PLACEHOLDER__;
92
92
93
93
cssFilePaths.forEach(cssPath => {
94
- let href = ''
95
- const baseUrl = base || curUrl
96
- if (baseUrl && baseUrl !== '/') {
97
- href = [baseUrl, assetsDir, cssPath].filter(Boolean).map(part => part.endsWith('/') ? part.substring(0, part.length - 1) : part).join('/')
94
+ let href = '';
95
+ const baseUrl = base || curUrl;
96
+ if (baseUrl) {
97
+ const trimmer = {
98
+ trailing: (path) => (path.endsWith('/') ? path.slice(0, -1) : path),
99
+ leading: (path) => (path.startsWith('/') ? path.slice(1) : path)
100
+ }
101
+ const isAbsoluteUrl = (url) => url.startsWith('http') || url.startsWith('//');
102
+
103
+ const cleanBaseUrl = trimmer.trailing(baseUrl);
104
+ const cleanCssPath = trimmer.leading(cssPath);
105
+ const cleanCurUrl = trimmer.trailing(curUrl);
106
+
107
+ if (isAbsoluteUrl(baseUrl)) {
108
+ href = [cleanBaseUrl, cleanCssPath].filter(Boolean).join('/');
109
+ } else {
110
+ href = [cleanCurUrl + cleanBaseUrl, cleanCssPath].filter(Boolean).join('/');
111
+ }
98
112
} else {
99
- href = curUrl + cssPath
113
+ href = cssPath;
100
114
}
101
115
102
116
if (href in seen) return;
@@ -180,7 +194,7 @@ export function prodExposePlugin(
180
194
. replace (
181
195
'__VITE_ASSETS_DIR_PLACEHOLDER__' ,
182
196
`'${ viteConfigResolved . config ?. build ?. assetsDir || '' } '`
183
- ) ;
197
+ )
184
198
185
199
const filepathMap = new Map ( )
186
200
const getFilename = ( name ) => parse ( parse ( name ) . name ) . name
0 commit comments