From d1efe364318906ef4f011447e673a8e2efd24f9b Mon Sep 17 00:00:00 2001 From: Day Date: Tue, 30 Jun 2020 23:14:42 +0800 Subject: [PATCH] feat: distinguish options for different CSS preprocessing languages --- src/index.ts | 25 +++++++++++++++++++++---- 1 file changed, 21 insertions(+), 4 deletions(-) diff --git a/src/index.ts b/src/index.ts index 57f147e..0b18a03 100644 --- a/src/index.ts +++ b/src/index.ts @@ -183,6 +183,25 @@ export default function PluginVue(userOptions: Partial = {}): Plugin { } else if (query.type === 'style') { debug(`transform(${id})`) const block = descriptor.styles[query.index]! + + let preprocessOptions = options.preprocessOptions || {} + const preprocessLang = (options.preprocessStyles + ? block.lang + : undefined) as SFCAsyncStyleCompileOptions['preprocessLang'] + + if (preprocessLang) { + preprocessOptions = preprocessOptions[preprocessLang] || {} + if ( + ['scss', 'sass'].includes(preprocessLang) && + !preprocessOptions.includePaths + ) { + preprocessOptions = { + includePaths: ['node_modules'], + ...preprocessOptions, + } + } + } + const result = await compileStyleAsync({ filename: query.filename, id: `data-v-${query.id!}`, @@ -192,11 +211,9 @@ export default function PluginVue(userOptions: Partial = {}): Plugin { postcssOptions: options.postcssOptions, postcssPlugins: options.postcssPlugins, modulesOptions: options.cssModulesOptions, - preprocessLang: options.preprocessStyles - ? (block.lang as any) - : undefined, + preprocessLang, preprocessCustomRequire: options.preprocessCustomRequire, - preprocessOptions: options.preprocessOptions || {}, + preprocessOptions, }) if (result.errors.length) {