@@ -187,6 +187,35 @@ export default function PluginVue(userOptions: Partial<Options> = {}): Plugin {
187
187
} else if ( query . type === 'style' ) {
188
188
debug ( `transform(${ id } )` )
189
189
const block = descriptor . styles [ query . index ] !
190
+
191
+ let preprocessOptions = options . preprocessOptions || { }
192
+ const preprocessLang = ( options . preprocessStyles
193
+ ? block . lang
194
+ : undefined ) as SFCAsyncStyleCompileOptions [ '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
+
190
219
const result = await compileStyleAsync ( {
191
220
filename : query . filename ,
192
221
id : `data-v-${ query . id ! } ` ,
@@ -197,11 +226,9 @@ export default function PluginVue(userOptions: Partial<Options> = {}): Plugin {
197
226
postcssOptions : options . postcssOptions ,
198
227
postcssPlugins : options . postcssPlugins ,
199
228
modulesOptions : options . cssModulesOptions ,
200
- preprocessLang : options . preprocessStyles
201
- ? ( block . lang as any )
202
- : undefined ,
229
+ preprocessLang,
203
230
preprocessCustomRequire : options . preprocessCustomRequire ,
204
- preprocessOptions : options . preprocessOptions || { } ,
231
+ preprocessOptions,
205
232
} )
206
233
207
234
if ( result . errors . length ) {
@@ -347,20 +374,14 @@ function getDescriptor(id: string) {
347
374
throw new Error ( `${ id } is not parsed yet` )
348
375
}
349
376
350
- function parseSFC (
351
- code : string ,
352
- id : string ,
353
- sourceRoot : string
354
- ) : { descriptor : SFCDescriptor ; errors : CompilerError [ ] } {
377
+ function parseSFC ( code : string , id : string , sourceRoot : string ) {
355
378
const { descriptor, errors } = parse ( code , {
356
379
sourceMap : true ,
357
380
filename : id ,
358
381
sourceRoot : sourceRoot ,
359
382
} )
360
-
361
383
cache . set ( id , descriptor )
362
-
363
- return { descriptor, errors }
384
+ return { descriptor, errors : errors }
364
385
}
365
386
366
387
function transformVueSFC (
@@ -537,21 +558,33 @@ function getCustomBlock(
537
558
return code
538
559
}
539
560
540
- function createRollupError ( 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
+ 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
+ }
555
588
}
556
589
}
557
590
0 commit comments