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

Commit

Permalink
feat: distinguish options for different CSS preprocessing languages
Browse files Browse the repository at this point in the history
  • Loading branch information
daychongyang authored and yyx990803 committed Jul 16, 2020
1 parent 2a7f92e commit 20f79f1
Showing 1 changed file with 25 additions and 4 deletions.
29 changes: 25 additions & 4 deletions src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -187,6 +187,29 @@ export default function PluginVue(userOptions: Partial<Options> = {}): 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] || preprocessOptions

if (
['scss', 'sass'].includes(preprocessLang) &&
!preprocessOptions.includePaths
) {
preprocessOptions = {
includePaths: ['node_modules'],
...preprocessOptions,
}
}
} else {
preprocessOptions = {}
}

const result = await compileStyleAsync({
filename: query.filename,
id: `data-v-${query.id!}`,
Expand All @@ -197,11 +220,9 @@ export default function PluginVue(userOptions: Partial<Options> = {}): 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) {
Expand Down

0 comments on commit 20f79f1

Please sign in to comment.