@@ -196,15 +196,21 @@ export default function PluginVue(userOptions: Partial<Options> = {}): Plugin {
196
196
if ( preprocessLang ) {
197
197
preprocessOptions =
198
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
- }
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
+ }
208
214
}
209
215
} else {
210
216
preprocessOptions = { }
@@ -368,20 +374,14 @@ function getDescriptor(id: string) {
368
374
throw new Error ( `${ id } is not parsed yet` )
369
375
}
370
376
371
- function parseSFC (
372
- code : string ,
373
- id : string ,
374
- sourceRoot : string
375
- ) : { descriptor : SFCDescriptor ; errors : CompilerError [ ] } {
377
+ function parseSFC ( code : string , id : string , sourceRoot : string ) {
376
378
const { descriptor, errors } = parse ( code , {
377
379
sourceMap : true ,
378
380
filename : id ,
379
381
sourceRoot : sourceRoot ,
380
382
} )
381
-
382
383
cache . set ( id , descriptor )
383
-
384
- return { descriptor, errors }
384
+ return { descriptor, errors : errors }
385
385
}
386
386
387
387
function transformVueSFC (
@@ -558,21 +558,33 @@ function getCustomBlock(
558
558
return code
559
559
}
560
560
561
- function createRollupError ( id : string , error : CompilerError ) : RollupError {
562
- return {
563
- id,
564
- plugin : 'vue' ,
565
- pluginCode : String ( error . code ) ,
566
- message : error . message ,
567
- frame : error . loc ! . source ,
568
- parserError : error ,
569
- loc : error . loc
570
- ? {
571
- file : id ,
572
- line : error . loc . start . line ,
573
- column : error . loc . start . column ,
574
- }
575
- : undefined ,
561
+ function createRollupError (
562
+ id : string ,
563
+ error : CompilerError | SyntaxError
564
+ ) : RollupError {
565
+ if ( 'code' in error ) {
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
+ }
576
588
}
577
589
}
578
590
0 commit comments