From eeb90507539d5d59790ef94414eb3966e558eae6 Mon Sep 17 00:00:00 2001 From: HomyeeKing Date: Fri, 26 Mar 2021 15:52:09 +0800 Subject: [PATCH] fix: loadPreprocessor from both configFile path and cwd --- packages/vite/src/node/plugins/css.ts | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/packages/vite/src/node/plugins/css.ts b/packages/vite/src/node/plugins/css.ts index 89b751d7061882..5ada90a106283d 100644 --- a/packages/vite/src/node/plugins/css.ts +++ b/packages/vite/src/node/plugins/css.ts @@ -568,7 +568,7 @@ async function compileCSS( opts.filename = cleanUrl(id) const preprocessResult = await preProcessor( code, - config.root, + [config.root, config.configFile || ''], opts, atImportResolvers ) @@ -861,7 +861,7 @@ type PreprocessorAdditionalData = type StylePreprocessor = ( source: string, - root: string, + root: string[], options: { [key: string]: any additionalData?: PreprocessorAdditionalData @@ -880,19 +880,19 @@ export interface StylePreprocessorResults { const loadedPreprocessors: Partial> = {} -function loadPreprocessor(lang: PreprocessLang.scss, root: string): typeof Sass -function loadPreprocessor(lang: PreprocessLang.sass, root: string): typeof Sass -function loadPreprocessor(lang: PreprocessLang.less, root: string): typeof Less +function loadPreprocessor(lang: PreprocessLang.scss, root: string[]): typeof Sass +function loadPreprocessor(lang: PreprocessLang.sass, root: string[]): typeof Sass +function loadPreprocessor(lang: PreprocessLang.less, root: string[]): typeof Less function loadPreprocessor( lang: PreprocessLang.stylus, - root: string + root: string[] ): typeof Stylus -function loadPreprocessor(lang: PreprocessLang, root: string): any { +function loadPreprocessor(lang: PreprocessLang, root: string[]): any { if (lang in loadedPreprocessors) { return loadedPreprocessors[lang] } try { - const resolved = require.resolve(lang, { paths: [root] }) + const resolved = require.resolve(lang, { paths: root }) return (loadedPreprocessors[lang] = require(resolved)) } catch (e) { throw new Error(