Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings
This repository was archived by the owner on Jan 18, 2022. It is now read-only.

Commit860595e

Browse files
author
Day
authored
feat: distinguish options for different CSS preprocessing languages (#366)
1 parent2a7f92e commit860595e

File tree

1 file changed

+60
-27
lines changed

1 file changed

+60
-27
lines changed

‎src/index.ts

Lines changed: 60 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -187,6 +187,35 @@ export default function PluginVue(userOptions: Partial<Options> = {}): Plugin {
187187
}elseif(query.type==='style'){
188188
debug(`transform(${id})`)
189189
constblock=descriptor.styles[query.index]!
190+
191+
letpreprocessOptions=options.preprocessOptions||{}
192+
constpreprocessLang=(options.preprocessStyles
193+
?block.lang
194+
:undefined)asSFCAsyncStyleCompileOptions['preprocessLang']
195+
196+
if(preprocessLang){
197+
preprocessOptions=
198+
preprocessOptions[preprocessLang]||preprocessOptions
199+
// include node_modules for imports by default
200+
switch(preprocessLang){
201+
case'scss':
202+
case'sass':
203+
preprocessOptions={
204+
includePaths:['node_modules'],
205+
...preprocessOptions,
206+
}
207+
break
208+
case'less':
209+
case'stylus':
210+
preprocessOptions={
211+
paths:['node_modules'],
212+
...preprocessOptions,
213+
}
214+
}
215+
}else{
216+
preprocessOptions={}
217+
}
218+
190219
constresult=awaitcompileStyleAsync({
191220
filename:query.filename,
192221
id:`data-v-${query.id!}`,
@@ -197,11 +226,9 @@ export default function PluginVue(userOptions: Partial<Options> = {}): Plugin {
197226
postcssOptions:options.postcssOptions,
198227
postcssPlugins:options.postcssPlugins,
199228
modulesOptions:options.cssModulesOptions,
200-
preprocessLang:options.preprocessStyles
201-
?(block.langasany)
202-
:undefined,
229+
preprocessLang,
203230
preprocessCustomRequire:options.preprocessCustomRequire,
204-
preprocessOptions:options.preprocessOptions||{},
231+
preprocessOptions,
205232
})
206233

207234
if(result.errors.length){
@@ -347,20 +374,14 @@ function getDescriptor(id: string) {
347374
thrownewError(`${id} is not parsed yet`)
348375
}
349376

350-
functionparseSFC(
351-
code:string,
352-
id:string,
353-
sourceRoot:string
354-
):{descriptor:SFCDescriptor;errors:CompilerError[]}{
377+
functionparseSFC(code:string,id:string,sourceRoot:string){
355378
const{ descriptor, errors}=parse(code,{
356379
sourceMap:true,
357380
filename:id,
358381
sourceRoot:sourceRoot,
359382
})
360-
361383
cache.set(id,descriptor)
362-
363-
return{ descriptor, errors}
384+
return{ descriptor,errors:errors}
364385
}
365386

366387
functiontransformVueSFC(
@@ -537,21 +558,33 @@ function getCustomBlock(
537558
returncode
538559
}
539560

540-
functioncreateRollupError(id:string,error:CompilerError):RollupError{
541-
return{
542-
id,
543-
plugin:'vue',
544-
pluginCode:String(error.code),
545-
message:error.message,
546-
frame:error.loc!.source,
547-
parserError:error,
548-
loc:error.loc
549-
?{
550-
file:id,
551-
line:error.loc.start.line,
552-
column:error.loc.start.column,
553-
}
554-
:undefined,
561+
functioncreateRollupError(
562+
id:string,
563+
error:CompilerError|SyntaxError
564+
):RollupError{
565+
if('code'inerror){
566+
return{
567+
id,
568+
plugin:'vue',
569+
pluginCode:String(error.code),
570+
message:error.message,
571+
frame:error.loc!.source,
572+
parserError:error,
573+
loc:error.loc
574+
?{
575+
file:id,
576+
line:error.loc.start.line,
577+
column:error.loc.start.column,
578+
}
579+
:undefined,
580+
}
581+
}else{
582+
return{
583+
id,
584+
plugin:'vue',
585+
message:error.message,
586+
parserError:error,
587+
}
555588
}
556589
}
557590

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp