Skip to content
This repository was archived by the owner on Jan 18, 2022. It is now read-only.

Commit d1efe36

Browse files
committed
feat: distinguish options for different CSS preprocessing languages
1 parent 1f71e17 commit d1efe36

File tree

1 file changed

+21
-4
lines changed

1 file changed

+21
-4
lines changed

Diff for: src/index.ts

+21-4
Original file line numberDiff line numberDiff line change
@@ -183,6 +183,25 @@ export default function PluginVue(userOptions: Partial<Options> = {}): Plugin {
183183
} else if (query.type === 'style') {
184184
debug(`transform(${id})`)
185185
const block = descriptor.styles[query.index]!
186+
187+
let preprocessOptions = options.preprocessOptions || {}
188+
const preprocessLang = (options.preprocessStyles
189+
? block.lang
190+
: undefined) as SFCAsyncStyleCompileOptions['preprocessLang']
191+
192+
if (preprocessLang) {
193+
preprocessOptions = preprocessOptions[preprocessLang] || {}
194+
if (
195+
['scss', 'sass'].includes(preprocessLang) &&
196+
!preprocessOptions.includePaths
197+
) {
198+
preprocessOptions = {
199+
includePaths: ['node_modules'],
200+
...preprocessOptions,
201+
}
202+
}
203+
}
204+
186205
const result = await compileStyleAsync({
187206
filename: query.filename,
188207
id: `data-v-${query.id!}`,
@@ -192,11 +211,9 @@ export default function PluginVue(userOptions: Partial<Options> = {}): Plugin {
192211
postcssOptions: options.postcssOptions,
193212
postcssPlugins: options.postcssPlugins,
194213
modulesOptions: options.cssModulesOptions,
195-
preprocessLang: options.preprocessStyles
196-
? (block.lang as any)
197-
: undefined,
214+
preprocessLang,
198215
preprocessCustomRequire: options.preprocessCustomRequire,
199-
preprocessOptions: options.preprocessOptions || {},
216+
preprocessOptions,
200217
})
201218

202219
if (result.errors.length) {

0 commit comments

Comments
 (0)