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

Commit 20f79f1

Browse files
daychongyangyyx990803
authored andcommitted
feat: distinguish options for different CSS preprocessing languages
1 parent 2a7f92e commit 20f79f1

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
@@ -187,6 +187,29 @@ export default function PluginVue(userOptions: Partial<Options> = {}): Plugin {
187187
} else if (query.type === 'style') {
188188
debug(`transform(${id})`)
189189
const block = descriptor.styles[query.index]!
190+
191+
let preprocessOptions = options.preprocessOptions || {}
192+
const preprocessLang = (options.preprocessStyles
193+
? block.lang
194+
: undefined) as SFCAsyncStyleCompileOptions['preprocessLang']
195+
196+
if (preprocessLang) {
197+
preprocessOptions =
198+
preprocessOptions[preprocessLang] || preprocessOptions
199+
200+
if (
201+
['scss', 'sass'].includes(preprocessLang) &&
202+
!preprocessOptions.includePaths
203+
) {
204+
preprocessOptions = {
205+
includePaths: ['node_modules'],
206+
...preprocessOptions,
207+
}
208+
}
209+
} else {
210+
preprocessOptions = {}
211+
}
212+
190213
const result = await compileStyleAsync({
191214
filename: query.filename,
192215
id: `data-v-${query.id!}`,
@@ -197,11 +220,9 @@ export default function PluginVue(userOptions: Partial<Options> = {}): Plugin {
197220
postcssOptions: options.postcssOptions,
198221
postcssPlugins: options.postcssPlugins,
199222
modulesOptions: options.cssModulesOptions,
200-
preprocessLang: options.preprocessStyles
201-
? (block.lang as any)
202-
: undefined,
223+
preprocessLang,
203224
preprocessCustomRequire: options.preprocessCustomRequire,
204-
preprocessOptions: options.preprocessOptions || {},
225+
preprocessOptions,
205226
})
206227

207228
if (result.errors.length) {

0 commit comments

Comments
 (0)