@@ -192,15 +192,21 @@ export default function PluginVue(userOptions: Partial<Options> = {}): Plugin {
192
192
if ( preprocessLang ) {
193
193
preprocessOptions =
194
194
preprocessOptions [ preprocessLang ] || preprocessOptions
195
-
196
- if (
197
- [ 'scss' , 'sass' ] . includes ( preprocessLang ) &&
198
- ! preprocessOptions . includePaths
199
- ) {
200
- preprocessOptions = {
201
- includePaths : [ 'node_modules' ] ,
202
- ...preprocessOptions ,
203
- }
195
+ // include node_modules for imports by default
196
+ switch ( preprocessLang ) {
197
+ case 'scss' :
198
+ case 'sass' :
199
+ preprocessOptions = {
200
+ includePaths : [ 'node_modules' ] ,
201
+ ...preprocessOptions ,
202
+ }
203
+ break
204
+ case 'less' :
205
+ case 'stylus' :
206
+ preprocessOptions = {
207
+ paths : [ 'node_modules' ] ,
208
+ ...preprocessOptions ,
209
+ }
204
210
}
205
211
} else {
206
212
preprocessOptions = { }
@@ -363,21 +369,15 @@ function getDescriptor(id: string) {
363
369
throw new Error ( `${ id } is not parsed yet` )
364
370
}
365
371
366
- function parseSFC (
367
- code : string ,
368
- id : string ,
369
- sourceRoot : string
370
- ) : { descriptor : SFCDescriptor ; errors : CompilerError [ ] } {
372
+ function parseSFC ( code : string , id : string , sourceRoot : string ) {
371
373
const { descriptor, errors } = parse ( code , {
372
374
sourceMap : true ,
373
375
filename : id ,
374
376
sourceRoot : sourceRoot ,
375
377
pad : 'line' ,
376
378
} )
377
-
378
379
cache . set ( id , descriptor )
379
-
380
- return { descriptor, errors }
380
+ return { descriptor, errors : errors }
381
381
}
382
382
383
383
function transformVueSFC (
@@ -548,21 +548,33 @@ function getCustomBlock(
548
548
return code
549
549
}
550
550
551
- function createRollupError ( id : string , error : CompilerError ) : RollupError {
552
- return {
553
- id,
554
- plugin : 'vue' ,
555
- pluginCode : String ( error . code ) ,
556
- message : error . message ,
557
- frame : error . loc ! . source ,
558
- parserError : error ,
559
- loc : error . loc
560
- ? {
561
- file : id ,
562
- line : error . loc . start . line ,
563
- column : error . loc . start . column ,
564
- }
565
- : undefined ,
551
+ function createRollupError (
552
+ id : string ,
553
+ error : CompilerError | SyntaxError
554
+ ) : RollupError {
555
+ if ( 'code' in error ) {
556
+ return {
557
+ id,
558
+ plugin : 'vue' ,
559
+ pluginCode : String ( error . code ) ,
560
+ message : error . message ,
561
+ frame : error . loc ! . source ,
562
+ parserError : error ,
563
+ loc : error . loc
564
+ ? {
565
+ file : id ,
566
+ line : error . loc . start . line ,
567
+ column : error . loc . start . column ,
568
+ }
569
+ : undefined ,
570
+ }
571
+ } else {
572
+ return {
573
+ id,
574
+ plugin : 'vue' ,
575
+ message : error . message ,
576
+ parserError : error ,
577
+ }
566
578
}
567
579
}
568
580
0 commit comments