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

Commit a83d2dd

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

File tree

1 file changed

+25
-4
lines changed

1 file changed

+25
-4
lines changed

Diff for: src/index.ts

+25-4
Original file line numberDiff line numberDiff line change
@@ -183,6 +183,29 @@ 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 =
194+
preprocessOptions[preprocessLang] || preprocessOptions
195+
196+
if (
197+
['scss', 'sass'].includes(preprocessLang) &&
198+
!preprocessOptions.includePaths
199+
) {
200+
preprocessOptions = {
201+
includePaths: ['node_modules'],
202+
...preprocessOptions,
203+
}
204+
}
205+
} else {
206+
preprocessOptions = {}
207+
}
208+
186209
const result = await compileStyleAsync({
187210
filename: query.filename,
188211
id: `data-v-${query.id!}`,
@@ -192,11 +215,9 @@ export default function PluginVue(userOptions: Partial<Options> = {}): Plugin {
192215
postcssOptions: options.postcssOptions,
193216
postcssPlugins: options.postcssPlugins,
194217
modulesOptions: options.cssModulesOptions,
195-
preprocessLang: options.preprocessStyles
196-
? (block.lang as any)
197-
: undefined,
218+
preprocessLang,
198219
preprocessCustomRequire: options.preprocessCustomRequire,
199-
preprocessOptions: options.preprocessOptions || {},
220+
preprocessOptions,
200221
})
201222

202223
if (result.errors.length) {

0 commit comments

Comments
 (0)