From 93667de516ac8529079f950c37784d24e1e7ad57 Mon Sep 17 00:00:00 2001 From: bluwy Date: Tue, 29 Nov 2022 13:52:39 +0800 Subject: [PATCH] fix: handle generically --- packages/vite/src/node/plugins/css.ts | 15 +++++++++++++-- 1 file changed, 13 insertions(+), 2 deletions(-) diff --git a/packages/vite/src/node/plugins/css.ts b/packages/vite/src/node/plugins/css.ts index f7e5b75ce955e2..0277a6594a3445 100644 --- a/packages/vite/src/node/plugins/css.ts +++ b/packages/vite/src/node/plugins/css.ts @@ -1499,9 +1499,20 @@ function loadPreprocessor( } } -// in unix, scss might append http://localhost in environments that shim `location` +// in unix, scss might append `location.href` in environments that shim `location` // see https://github.com/sass/dart-sass/issues/710 -const cleanScssBugUrl = (url: string) => url.replace(/^http:\/\/localhost/, '') +function cleanScssBugUrl(url: string) { + if ( + // check bug via `window` and `location` global + typeof window !== 'undefined' && + typeof location !== 'undefined' + ) { + const prefix = location.href.replace(/\/$/, '') + return url.replace(prefix, '') + } else { + return url + } +} function fixScssBugImportValue( data: Sass.ImporterReturnType