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 committed Jul 3, 2020
1 parent 1f71e17 commit a83d2dd
Showing 1 changed file with 25 additions and 4 deletions.
29 changes: 25 additions & 4 deletions src/index.ts
Expand Up @@ -183,6 +183,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 @@ -192,11 +215,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 a83d2dd

Please sign in to comment.